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";
preg_match stops looking after the first match. preg_match_all , on the other hand, continues to look until it finishes processing the entire string. Once match is found, it uses the remainder of the string to try and apply another match.
PHP | preg_match() Function. This function searches string for pattern, returns true if pattern exists, otherwise returns false. Usually search starts from beginning of subject string. The optional parameter offset is used to specify the position from where to start the search.
Return Values ¶ preg_match() returns 1 if the pattern matches given subject , 0 if it does not, or false on failure. This function may return Boolean false , but may also return a non-Boolean value which evaluates to false . Please read the section on Booleans for more information.
preg_match() in PHP – this function is used to perform pattern matching in PHP on a string. It returns true if a match is found and false if a match is not found. preg_split() in PHP – this function is used to perform a pattern match on a string and then split the results into a numeric array.
preg_last_error() after the second call returns 2 (=PREG_BACKTRACK_LIMIT_ERROR) so you might want to raise this value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With