字符串 preg_match_all 的最大长度可以匹配获取吗? [英] Maximum length of string preg_match_all can match and acquire?

查看:44
本文介绍了字符串 preg_match_all 的最大长度可以匹配获取吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 preg_match_all() 解析一些网页,其中一些非常大,有几 MB 大小.其中一个正则表达式匹配一些文本字符串,这些字符串太大以至于它们似乎无法匹配和获取它们.它只是返回一个空字符串.

I'm trying to parse some web pages with preg_match_all() and some of them are quite large as several MBs in size. And one of the regular expressions matches some text strings that are so large that they don't seem to be able to match and acquire them. It simply returns an empty string.

当我手动选择它并将其保存为 .txt 文件时,其中一个字符串为 1.32MB 或 1,393,557 字节.

One of the strings is 1.32MB or 1,393,557 bytes when I manually selected it and saved it as a .txt file.

当字符串短到数万字节时,正则表达式成功匹配并获取它.

When the string is much shorter as just tens of thousands of bytes, that regular expression successfully matches and acquires it.

所以我的问题是,在我看来,字符串 preg_match_all() 可以匹配的限制/最大长度是什么,它是什么以及如何将其设置得更大?

So my question is, as it occurs to me there's a limit / maximum length of string preg_match_all() can match, what is it and how can I set it larger?

推荐答案

ini_set('pcre.backtrack_limit', '1048576'); 设置为您想要的脚本或 php 中的任何内容.ini 文件供全球使用.(示例为 1mb)

Set the ini_set('pcre.backtrack_limit', '1048576'); to whatever you want in your script or on your php.ini file for global use. (example is 1mb)

归功于:http://www.karlrixon.co.uk/writing/php-regular-expression-fails-silently-on-long-strings/

这篇关于字符串 preg_match_all 的最大长度可以匹配获取吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆