The PHP manual states that preg_match_all will return the number of full pattern matches (which might be zero), or FALSE if an error occurred. In my pattern variable, I have '#foo#'. The input string I'm searching through ($in) is "1234 4332 foxo". Below is my conditional code where $m = matches and $filter = preg_match_all($p, $in, $m):
Code: Select all
if(0 !== $filter){//if a match is found...
echo 'A match has been found.<br />';
}elseif(FALSE == $filter){//if error occurs...
echo 'An error has been found.<br />';
}else{//if good filter...
echo 'Good filter.';
}
Is it necessary to have a condition setup for the ERROR possibility or what? I keep tripping this when I don't even have "foo" within the input string and I can't seem to understand why... Also, I tried to make the first conditional be "if(FALSE !== $filter && $m > 0)", and it didn't work. Why?
Any input is appreciated.