Preg_match: the string that matches the regular expression. There will be some problems in the strings of preg_match regular Matching. next I will introduce how to solve the problem of long strings with incorrect ideas. For example, if the preg_match_all regular expression preg_match matches a string that matches the regular expression, some problems may occur. next I will introduce how to solve the problem of incorrect ideas when long strings exist.
Example
Preg_match_all: regex matches all connection addresses of strings.
The code is as follows: |
|
$ Str = '4 5 6 '; $ Ymd = date ("y"). "/". date ("m-d "); $ B = preg_match_all ('/(.*?) /', $ A, $ c, preg_set_order ); |
However, if you use the preg_match regular expression to extract the target content, the problem may occur,
The code is tested dead.
Later, we found that the value of "pcre. backtrack_limit" is set to 100000 by default.
Solution:
The code is as follows: |
|
Ini_set ('pcre. backtrack_limit ', 999999999 );
|
Note: this parameter is available after php 5.2.0.
For more information, see pcre. recursion_limit.
Pcre. recursion_limit is the recursive limitation of PCRE. if this item is set to a large value, it will consume the available stacks of all processes and eventually cause PHP to crash.
You can also modify the configuration to limit
The code is as follows: |
|
Ini_set ('pcre. recursion_limit ', 99999 ); |
In actual project applications, it is best to restrict the memory:
The code is as follows: |
|
Ini_set ('memory _ limit ', '64m '); |
Bytes. Example: preg_match_all regular...