php regular length limit

巴扎黑
Release: 2016-11-24 09:52:42
Original
1281 people have browsed it

Scenario: When using regular expressions to match page content (preg_match('/(.*)(.*)(.*)/Uis',$str)), it is found that sometimes Normal matching, sometimes not, you can analyze the page structure and find that there is no change, the only change is the page size.

Reason: PHP limits the matching length of regular expressions. You can see the following with phpinfo

pcre.backtrack_limit 100000 100000
pcre.recursion_limit 100000 100000

I found that it is only 100K, which is definitely not enough if you are grabbing a web page , in fact, just make the corresponding settings on php.ini (or change the size of these two values)

pcre.backtrack_limit=-1
pcre.recursion_limit=-1

Attached note:

[Pcre]
; Perl compatible regular expression module
pcre.backtrack_limit = 100000
; The maximum number of backtracking steps for PCRE.
pcre.recursion_limit = 100000
; The maximum recursion depth of PCRE.
; If you set this value very high, you may run out of process stack space and cause PHP to crash.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!