Preg_match has a line size limit

preg_match has str limit in 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"; 
+4
source share
1 answer

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

+6
source

All Articles