简体   繁体   English

PHP preg_match停止响应字符串中一定数量的字符

[英]PHP preg_match stops responding at certain number of characters in string

Is there some kind of PHP configuration setting that would affect the length of string being passed into preg_match or preg_match_all? 是否有某种PHP配置设置会影响传递给preg_match或preg_match_all的字符串的长度?

I have the following which I am trying to test to work out what is going wrong for me: 我尝试测试以下内容,以找出问题所在:

    $re = "/\[\[section\:(.*?)\]\]((.|\n)*?)\[\[endsection\]\]/"; 
    $str = "[[section:body]]
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    [[endsection]]

    other stuff here"; 

    preg_match_all($re, $str, $matches);
    var_dump($matches);

Now if I run that it's fine, it returns the results pretty much instantly. 现在,如果我运行正常,它将立即返回结果。

But if I add one more line to the $str variable and run it again, it just spins and spins and then I get web page cannot be displayed. 但是,如果我再向$ str变量添加一行并再次运行它,它只会旋转,然后我无法显示网页。

But if I then run that exact same thing on writecodeonline.com/php it works fine and returns instantly. 但是,如果我随后在writecodeonline.com/php上运行完全相同的操作,它将正常工作并立即返回。

I'm not getting any errors in my php error log or my apache error logs, it just refuses to do anything once it hits that certain characters (it seems to be that as soon as it hits 707 characters it stops responding. 我的php错误日志或apache错误日志中没有任何错误,一旦击中某些字符,它只是拒绝执行任何操作(似乎击中707个字符后,它将停止响应。

Has anyone come across this sort of issue before? 有人遇到过这种问题吗? Is it just some configuration setting I need to change? 这只是我需要更改的一些配置设置吗?

Cheers. 干杯。

Yes, there is the backtrack-limit 是的,有回溯限制

You can configure this in your php.ini file. 您可以在php.ini文件中进行配置。

To be honest, a quick google search would have solved your problem... 老实说,快速的Google搜索可以解决您的问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM