各位大神,小弟在使用preg_match_all时候遇到的一个奇怪的问题
我在使用preg_match_all的时候匹配一个比较长串的字符串的时候,apache就会崩溃,最后显示页面加载失败
后来上网查了一下说是要把
ini_set('pcre.backtrack_limit', 999999999);
ini_set('pcre.recursion_limit', 99999);
设成这样的,但是发现并没有什么用,折腾了好长时间没有办法解决,恳请大神们指点
下面的链接是我参考原文,上面两个解决思路也是从下面链接上复制而来的
http://www.php230.com/1410840481.html
回复讨论(解决方案)
那么你的 规则串 和 待匹配文本 都是什么样自的呢?
凡事都有个度,超过了自然就会出问题
比如 向后引用 不宜超过 9 个,超过了就会产生歧义
数据库的 Text 类型 只能存储 64k 内容,preg 函数在实现时也会考虑这个因素,预留巨大的状态转移表空间也是一种浪费
那么你的 规则串 和 待匹配文本 都是什么样自的呢?
凡事都有个度,超过了自然就会出问题
比如 向后引用 不宜超过 9 个,超过了就会产生歧义
数据库的 Text 类型 只能存储 64k 内容,preg 函数在实现时也会考虑这个因素,预留巨大的状态转移表空间也是一种浪费
学习了·····PHP精度问题是个很大的问题
那么你的 规则串 和 待匹配文本 都是什么样自的呢?
凡事都有个度,超过了自然就会出问题
比如 向后引用 不宜超过 9 个,超过了就会产生歧义
数据库的 Text 类型 只能存储 64k 内容,preg 函数在实现时也会考虑这个因素,预留巨大的状态转移表空间也是一种浪费
正则表达式是这样的
$pattern = '/\{(\{(\w+)(?:(?!\{\{).|\n)+\{\/\2\})\}/';
字符串是:
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> {{foreach ($message1 as $key1 => $value1)} {$key1} => {foreach ($value1 as $key2 => $value2)} {foreach ($value2 as $key3 => $value3)} {if($value3 == 0)} <p>{$key3}=>female</p> {else if($value3 == 1)} <p>{$key3}=>male</p> {else} <p>{$key3}=>{$value3}</p> {/if} {/foreach} {/foreach} {/foreach}} </body></html>
那么你的 规则串 和 待匹配文本 都是什么样自的呢?
凡事都有个度,超过了自然就会出问题
比如 向后引用 不宜超过 9 个,超过了就会产生歧义
数据库的 Text 类型 只能存储 64k 内容,preg 函数在实现时也会考虑这个因素,预留巨大的状态转移表空间也是一种浪费
正则表达式是这样的
$pattern = '/\{(\{(\w+)(?:(?!\{\{).|\n)+\{\/\2\})\}/';
字符串是:
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> {{foreach ($message1 as $key1 => $value1)} {$key1} => {foreach ($value1 as $key2 => $value2)} {foreach ($value2 as $key3 => $value3)} {if($value3 == 0)} <p>{$key3}=>female</p> {else if($value3 == 1)} <p>{$key3}=>male</p> {else} <p>{$key3}=>{$value3}</p> {/if} {/foreach} {/foreach} {/foreach}} </body></html>
preg_match_all($pattern, $this->content, $matches);
$this->content就是上面的字符串的内容,在运行preg_match_all的时候,程序就崩溃了
那么你的 规则串 和 待匹配文本 都是什么样自的呢?
凡事都有个度,超过了自然就会出问题
比如 向后引用 不宜超过 9 个,超过了就会产生歧义
数据库的 Text 类型 只能存储 64k 内容,preg 函数在实现时也会考虑这个因素,预留巨大的状态转移表空间也是一种浪费
正则表达式是这样的
$pattern = '/\{(\{(\w+)(?:(?!\{\{).|\n)+\{\/\2\})\}/';
字符串是:
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> {{foreach ($message1 as $key1 => $value1)} {$key1} => {foreach ($value1 as $key2 => $value2)} {foreach ($value2 as $key3 => $value3)} {if($value3 == 0)} <p>{$key3}=>female</p> {else if($value3 == 1)} <p>{$key3}=>male</p> {else} <p>{$key3}=>{$value3}</p> {/if} {/foreach} {/foreach} {/foreach}} </body></html>
preg_match_all($pattern, $this->content, $matches);
$this->content就是上面的字符串的内容,在运行preg_match_all的时候,程序就崩溃了
再补充一点,这个正则表达式是要匹配{{foreach ...}........{/foreach}}的内容
另外我测试过了,把上面的字符串长度剪短,变成下面这样的,preg_match_all就可以正常的运行,
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> {{foreach ($message1 as $key1 => $value1)} {$key1} => {foreach ($value1 as $key2 => $value2)} {foreach ($value2 as $key3 => $value3)} <p>{$key3}=>{$value3}</p> {/foreach} {/foreach} {/foreach}} </body></html>
但是如果剪短的话,就不能完成我的需求,请大神指点

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
