Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the analysis of the idea of solving the limitation of too many characters in preg_match matching

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to solve the limitation of too many characters in preg_match matching. the content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

But this is not stated in the official documents.

So start testing: the string to be matched continues to shorten until it matches normally when it is shrunk to the original 1ax 5, so it is more certain.

After searching google, I finally found the solution: add it to php.ini (wherever I put it, I put it directly on the first line)

Pcre.backtrack_limit=-1

Once again, use the preg_match function to test that a string of about 1300 lines and tens of thousands of characters can match.

In the project, using preg_match regularization to extract the target content, there is a problem with life or death, and the code is tested again and again.

It turns out that the default value of "pcre.backtrack_limit" is only 100000.

Solution: ini_set ('pcre.backtrack_limit', 999999999)

Note: this parameter is available after php version 5.2.0.

In addition, about: pcre.recursion_limit

Pcre.recursion_limit is a recursive limitation of PCRE, and if this item is set to a large value, it consumes the available stack of all processes, eventually causing PHP to crash.

You can also limit it by modifying the configuration: ini_set ('pcre.recursion_limit', 99999)

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

The above is the thinking analysis to solve the limitation of too many characters in preg_match matching. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 223

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report