preg 函数的最大字符数限制?

发布于 2024-09-02 09:45:41 字数 1276 浏览 4 评论 0原文

在我的网站上,我使用输出缓冲来获取所有输出,然后通过进程函数运行它,然后将其发送到浏览器(我不替换任何内容,只是将其分解为更易于管理的部分)。在这种特殊情况下,输出量很大,因为它列出了数据库中每个国家/地区(大约 240 个国家/地区)的标签。问题是,总的来说,我的 preg_match 函数似乎被跳过了,它绝对不执行任何操作并且不返回任何匹配项。但是,如果我删除部分标签(没有特定部分,只是随机部分以减少字符),则 preg_match 函数会再次起作用。我从标签中删除什么似乎并不重要,似乎只要删除这么多字符就可以了。 preg 函数可以处理的内容是否有某种上限,或者如果要扫描的数据太多,它会超时吗?

编辑:这是它运行的函数。

public function boom($data) {
    $number = preg_match_all("/(<!-- ([\w]+):start -->)\n?(.*?)\n?(<!-- \\2:stop -->)/s", $data, $matches, PREG_SET_ORDER);
    if ($number == 0) $data = array("content" => $data);
    else unset($data);
    foreach ($matches as $item):
        //$item[3] = preg_replace("/\n/", "", $item[3], 1);
        if (preg_match("/<!-- breaker -->/s", $item[3])) $data[$item[2]] = explode("<!-- breaker -->", $item[3]);
        else $data[$item[2]] = $item[3];
    endforeach;
    //die(var_dump($data));
    return $data;
}

这是发送到页面的未处理的输出。我已经确定是开头的 preg_match_all 在变量中返回 0 个匹配项,因此该函数只是将其接收到的整个字符串放入 $data['content'] 中并跳过其他所有内容。

http://pastebin.com/iGfM6gxx

我尝试将标签放在新行上,将它们折叠在一起,似乎没有任何作用。但正如上面所解释的,如果我删除它的随机部分,那么它就会顺利进行。该功能对于正常长度的所有其他页面都可以完美运行。

On my site I use output buffering to grab all the output and then run it through a process function before sending it out to the browser (I don't replace anything, just break it into more manageable pieces). In this particular case, there is a massive amount of output because it is listing out a label for every country in the database (around 240 countries). The problem is that in full, my preg_match functions seems to get skipped over, it does absolutely nothing and returns no matches. However, if I remove parts of the labels (no particular part, just random pieces to reduce characters) then the preg_match functions works again. It doesn't seem to matter what I remove from the label, it just seems to be that as long as I remove so many characters. Is there some sort of cap on what the preg functions can handle or will it time out if there is too much data to be scanned over?

Edit: Here is the function that it is run through.

public function boom($data) {
    $number = preg_match_all("/(<!-- ([\w]+):start -->)\n?(.*?)\n?(<!-- \\2:stop -->)/s", $data, $matches, PREG_SET_ORDER);
    if ($number == 0) $data = array("content" => $data);
    else unset($data);
    foreach ($matches as $item):
        //$item[3] = preg_replace("/\n/", "", $item[3], 1);
        if (preg_match("/<!-- breaker -->/s", $item[3])) $data[$item[2]] = explode("<!-- breaker -->", $item[3]);
        else $data[$item[2]] = $item[3];
    endforeach;
    //die(var_dump($data));
    return $data;
}

And here is the unprocessed output that is sent to the page. I have determined that it is the preg_match_all at the beginning that is returning 0 matches in the variable, so the function is simply throwing the entire string it received into $data['content'] and skipping everything else.

http://pastebin.com/iGfM6gxx

I've tried putting the labels on new lines, collapsing them together, nothing seems to work. But as explained above, if I remove random pieces of it, then it goes through fine. The function works perfectly fine with every other page of normal length.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-09-09 09:45:41

如果没有看到您的正则表达式和数据,很难说,但尝试更改 pcre.backtrack_limit / pcre.recursion_limit ( http://www.php.net/manual/en/pcre.configuration.php

it's hard to say without seeing your regex and data, but try to change pcre.backtrack_limit / pcre.recursion_limit ( http://www.php.net/manual/en/pcre.configuration.php)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文