开发者

PHP preg_match_all fails on long strings

Here's my code:

$long = str_repeat('a very long string text', 100); // try changing 100 to 5000

$str = <<<STR
<abc>a short string text</abc>
&开发者_StackOverflow社区lt;abc>$long</abc>
STR;

preg_match_all('@<abc>([^<>]+)</abc>@sU', $str, $matched);

print_r($matched);

And it works totally as expected. However, after you have changed 100 repetitions to 5000, run

print_r($matched);

And you will only get results for the short string occurrence.

My question is how to make preg_match or preg_match_all to work with large string texts (as large as 1MB or larger)?


You will probably need to increase the PCRE limits.

http://www.php.net/manual/en/pcre.configuration.php

Edit: But yeah, as ThiefMaster says, don't do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜