Home> php教程> php手册> body text

PHP中preg_match函数正则匹配的字符串长度问题,phppreg_match

WBOY
Release: 2016-06-13 09:03:03
Original
1023 people have browsed it

PHP中preg_match函数正则匹配的字符串长度问题,phppreg_match

项目中,用preg_match正则提取目标内容,死活有问题,代码测得死去活来。

后来怀疑PHP 的preg_match有字符串长度限制,果然,发现“pcre.backtrack_limit ”的值默认只设了100000。

解决办法:ini_set('pcre.backtrack_limit', 999999999);

注:这个参数在php 5.2.0版本之后可用。

另外说说关于:pcre.recursion_limit

pcre.recursion_limit是PCRE的递归限制,这个项如果设很大的值,会消耗所有进程的可用堆栈,最后导致PHP崩溃。

也可以通过修改配置来限制:ini_set('pcre.recursion_limit', 99999);

实际项目应用中,最好也对内存进行限定设置:ini_set('memory_limit', '64M'); , 这样就比较稳妥妥嘎。

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 Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!