Possible Duplicate:
Which method is preferred strstr or strpos ?
Hi!
Could you tell me which one is faster:
strstr($mystring, $findme);
OR
strpos($mystring, $findme);
OR
anything else
in finding the - first or any - occurrence of a string in another one?
Does it even matter in performance if I check the occurrence in a case-insensitive mode with stristr()
OR stripos()
?
In my case it doesn't matter in which exact position the given string is (if any), or how many times it occurs in the other one (if any), the only important question is if it even exists in the other string.
I've already found some comments about differences of speed in various articles (e.g. on php.net, someone says strstr() is faster in case there is a !== false check after strpos), but now I can't decide which is true.
If you know about any better methods of searching a string in another, please let me know!
Thank you very much for the relevant comments!
============
An example:
$mystring = 'blahblahblah';
$findme = 'bla';
if(strstr($mystring, $findme)){
echo 'got it';
}
else{
echo 'none';
}
echo PHP_EOL;
if(strpos($mystring, $findme) !== false){
echo 'got it';
}
else{
echo 'none';
}