Edit report at http://bugs.php.net/bug.php?id=53134&edit=1
ID: 53134
User updated by: xianhua dot zhou at gmail dot com
Reported by: xianhua dot zhou at gmail dot com
Summary: preg_replace_callback doesn't work with the "*?"
(lazy quantification)
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu 10.10
PHP Version: 5.3.3
Block user comment: N
New Comment:
Thanks for the reply. In this case, it would be better if php can show
an
error/warning message instead
of return NULL. e.g. like the "memory_limit" behavior.
Previous Comments:
------------------------------------------------------------------------
[2010-10-23 22:24:11] [email protected]
This is because the backtrack limit. Try setting a major backtrack_limt,
example: ini_set('pcre.backtrack_limit', PHP_INT_MAX);
Not a bug, it's an expected behavior from PCRE. :)
------------------------------------------------------------------------
[2010-10-22 07:17:19] xianhua dot zhou at gmail dot com
With the "*?" pattern, if the line
"str_repeat("a", 1024 * 100)"
changed to
"str_repeat("a", 1024 * 97)"
Then, it also works.
But if it's changed to "str_repeat("a", 1024 * 98)", then it doesn't
work.
------------------------------------------------------------------------
[2010-10-22 07:10:02] xianhua dot zhou at gmail dot com
Description:
------------
See the script below, if the $data is too big, then the script will be
failed, but if the regular expression from:
<pre>
!<script>([\s\S]*?)</script>!i
</pre>
changed to
</pre>
!<script>([\s\S]*)</script>!i
<pre>
Then, it works.
Test script:
---------------
<?php
$data = 'blabla <script>' . str_repeat("a", 1024 * 100) . '</script>';
$data = preg_replace_callback('!<script>([\s\S]*?)</script>!i',
function($matches) {
return $matches[1];
}, $data);
echo strlen($data);
?>
Expected result:
----------------
102407
Actual result:
--------------
0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53134&edit=1