1

how to increase search character limit? now in example is 3276 characters but in 3275 its works ok

ini_set("pcre.backtrack_limit", "23001337");
ini_set("pcre.recursion_limit", "23001337");

$str = "<div>";
for ($x=1;$x<=327;$x++){
    $str .= "1234567890";
}
$str .="123456";
$str .= "</div>";

$w1 = "/<div>((.*?|\n)*)<\/div>/";
preg_match_all($w1, $str, $matches);
print_r($matches);
Sławomir Kudła
  • 243
  • 2
  • 4
  • 14
  • I think it's an unpatched PHP bug https://bugs.php.net/bug.php?id=45735#1365812629 – MonkeyZeus Dec 28 '17 at 17:23
  • 1
    ^ or that - https://stackoverflow.com/questions/17926195/php-preg-match-length-3276-limit – splash58 Dec 28 '17 at 17:25
  • If changing http://php.net/manual/en/pcre.configuration.php does not work then you will probably need to modify your regular expression to avoid triggering this limitation. – MonkeyZeus Dec 28 '17 at 17:27
  • What's your actual problem? – revo Dec 28 '17 at 17:40
  • @revo `preg_match_all()` is failing when `$str` reaches some byte count. – MonkeyZeus Dec 28 '17 at 18:23
  • That's obvious but it's not clear whether or not he is trying to find a solution or reason. @MonkeyZeus – revo Dec 28 '17 at 18:31
  • [Don't parse HTML with regular expressions.](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – Sammitch Dec 28 '17 at 18:48

1 Answers1

2

Try disabling pcre.jit (don't use PCRE's just-in-time compilation):

<?php
ini_set("pcre.jit", "0");

$str = "<div>";
for ($x=1;$x<=327;$x++){
    $str .= "1234567890";
}
$str .="123456";
$str .= "</div>";

$w1 = "/<div>((.*?|\n)*)<\/div>/";
preg_match_all($w1, $str, $matches);
print_r($matches);
?>

You should execute preg_last_error() to know what has failed.

jeprubio
  • 17,312
  • 5
  • 45
  • 56