Home >Backend Development >PHP Tutorial >preg_match regular matching prompt pcre.backtrack_limit solution_PHP tutorial

preg_match regular matching prompt pcre.backtrack_limit solution_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:56:171027browse

This article introduces the solution to the preg_match regular matching prompt pcre.backtrack_limit. Friends in need can refer to it.


Using preg_match to extract the target content, there is a problem with life and death, and the code is dead or alive.

Later I suspected that PHP's preg_match had a string length limit. Sure enough, I found that the value of "pcre.backtrack_limit" was only set to 100000 by default.

Solution:

 代码如下 复制代码
ini_set('pcre.backtrack_limit', 999999999);

Note: This parameter is available after PHP 5.2.0 version.

Also, let’s talk about:
pcre.recursion_limit

pcre.recursion_limit is the recursion limit of PCRE. If this item is set to a large value, the available stacks of all processes will be consumed, and eventually PHP will crash.

You can also limit it by modifying the configuration: In actual project applications, it is best to limit the memory: ini_set('memory_limit', '64M'); , which is more secure.

The code is as follows
 代码如下 复制代码
ini_set('pcre.recursion_limit', 99999);
Copy code

ini_set('pcre.recursion_limit' , 99999);

 代码如下 复制代码

pcre.backtrack_limit=-1

References for other solutions
The code is as follows

Copy code
pcre.backtrack_limit=-1 For more details, please check: http://www.bKjia.c0m/phper/31/42927.htm http://www.bkjia.com/PHPjc/632177.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632177.htmlTechArticleThis article introduces the solution to the preg_match regular matching prompt pcre.backtrack_limit. Friends in need can refer to it. Use preg_match to extract the target content. If there is a problem, please replace...
Statement:
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