Home > Backend Development > PHP Tutorial > The string length problem of regular matching by preg_match function in PHP_PHP tutorial

The string length problem of regular matching by preg_match function in PHP_PHP tutorial

WBOY
Release: 2016-07-13 09:52:35
Original
966 people have browsed it

The string length problem of regular matching by preg_match function in PHP

This article mainly introduces the string length problem of regular matching by preg_match function in PHP. If you also encounter preg_match If the regular content is always blank or cannot be extracted, then you may have encountered this problem. Friends who need it can refer to it

In the project, preg_match is used to extract the target content. There are problems, and the code is tested to death.

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.

In addition, 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: ini_set('pcre.recursion_limit', 99999);

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1007650.htmlTechArticleThe string length problem of preg_match function regular matching in PHP This article mainly introduces the regular matching of preg_match function in PHP String length problem, if you also encounter preg_match regular...
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