2010-11-15 89 views
3

这里是我的代码:PHP preg_match_all长串失败

$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或更大)?

+0

看起来像你试图用正则表达式解析HTML/XML。 不要这样做。有关原因,请参阅http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454。 – ThiefMaster 2010-11-15 02:30:29

回答