The string length of Regular Expression matching in the preg_match function in PHP

Source: Internet
Author: User

The string length of Regular Expression matching in the preg_match function in PHP

This article mainly introduces the string length problem of Regular Expression matching in the preg_match function in PHP. If you also encounter the problem that the preg_match regular expression is always blank or cannot be extracted, this problem may occur. For more information, see

In the project, use the preg_match regular expression to extract the target content. If there is a problem with live or dead, the code will be tested dead.

Later, I suspect that PHP's preg_match has a string length limit, and found that the value of "pcre. backtrack_limit" is set to only 100000 by default.

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

In actual project applications, it is best to set the memory limit: ini_set ('memory _ limit ', '64m');, which makes it safer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.