这是我的代码:
$long = str_repeat('a very long string text', 100); // try changing 100 to 5000
$str = <<<STR
<abc>a short string text</abc>
<abc>$long</abc>
STR;
preg_match_all('@<abc>([^<>]+)</abc>@sU', $str, $matched);
print_r($matched);
它完全按照预期工作。但是,将 100 次重复更改为 5000 次后,运行
print_r($matched);
并且您只会获得短字符串出现的结果。
我的问题是如何使 preg_match 或 preg_match_all 处理大字符串文本(大至 1MB 或更大)?
您可能需要增加 PCRE 限制。
http://www.php.net/manual/en/pcre.configuration.php http://www.php.net/manual/en/pcre.configuration.php
编辑:但是,正如 ThiefMaster 所说,不要这样做。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)