php正则限制,正则表达式 – PHP preg_match_all限制

增加PCRE回溯和递归限制可能会解决问题,但是当数据大小达到新限制时仍会失败. (随着更多数据不能很好地扩展)

例:

// essential for huge PCREs

ini_set("pcre.backtrack_limit", "23001337");

ini_set("pcre.recursion_limit", "23001337");

// imagine your PCRE here...

?>

要真正解决底层问题,必须优化表达式并(如果可能)将复杂表达式拆分为“部分”并将一些逻辑移到PHP.我希望你通过阅读这个例子得到这个想法..而不是试图用一个PCRE直接找到子结构,我展示了一种更加“迭代”的方法,使用PHP更深入地进入结构.例:

$html = file_get_contents("huge_input.html");

// first find all tables, and work on those later

$res = preg_match_all("!

(?P.*)!isU", $html, $table_matches);

if ($res) foreach($table_matches['content'] as $table_match) {

// now find all cells in each table that was found earlier ..

$res = preg_match_all("!

(?P.*)!isU", $table_match, $cell_matches);

if ($res) foreach($cell_matches['content'] as $cell_match) {

// imagine going deeper and deeper into the structure here...

echo "found a table cell! content: ", $cell_match;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值