preg_match has string size limit

半腔热情 提交于 2019-12-19 07:24:27

问题


preg_match has limit of str on PHP 5.2.5

<?php
    $str1 = 'a@b%c@d' . str_repeat ('=', 33326);
    $str2 = 'a@b%c@d' . str_repeat ('=', 33327);
    $regexp = '/^(.*)@(.*)%(.*)$/si';

    echo preg_match ($regexp, $str1) ? "Correct " : "Wrong ";  // works correctly
    echo "\n";
    echo preg_match ($regexp, $str2) ? "Correct " : "Wrong ";  // exhibits the bug
    echo "\n";

回答1:


preg_last_error() after the second call returns 2 (=PREG_BACKTRACK_LIMIT_ERROR) so you might want to raise this value.



来源:https://stackoverflow.com/questions/6173223/preg-match-has-string-size-limit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!