简体   繁体   中英

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?

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.

But if I then run that exact same thing on writecodeonline.com/php it works fine and returns instantly.

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.

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.

To be honest, a quick google search would have solved your problem...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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