For single value check, which of both is preferred and why?
$string == 'The quick brown fox jumps over the lazy dog';
if(strpos($string, 'fox') !== false){
// do the routine
}
# versus
if(preg_match('/fox/i', $string)){
// do the routine
}
I would prefer the
strposoverpreg_match, because regexes are generally more expensive to execute.According to the official php docs for
preg_match: