|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-22 07:10 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 19:00:01 2025 UTC |
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.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. :)