Here are a few other answers (+ tests). I got to my question, which is almost the same (I did not understand yours when you ask).
In the meantime, I also made my own control test, which I performed 1,000,000 times for each corresponding function ( strstr() , strpos() , stristr() and stripos() ).
Here is the code:
<?php function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float) $usec + (float) $sec); } $mystring = 'blahblahblah'; $findme = 'bla'; echo 'strstr & strpos TEST:<pre>'; $time_start = getmicrotime(); for($i=0; $i<1000000; $i++) strstr($mystring, $findme); $time_needed_strstr = getmicrotime() - $time_start; echo 'strstr(): ', round( $time_needed_strstr , 8 ). PHP_EOL; $time_start = getmicrotime(); for($i=0; $i<1000000; $i++) stristr($mystring, $findme); $time_needed_stristr = getmicrotime() - $time_start; echo 'stristr(): ', round( $time_needed_stristr , 8 ) . PHP_EOL; $time_start = getmicrotime(); for($i=0; $i<1000000; $i++) strpos($mystring, $findme) !== false; $time_needed_strpos = getmicrotime() - $time_start; echo 'strpos() !== false: ', round( $time_needed_strpos , 8 ) . PHP_EOL; $time_start = getmicrotime(); for($i=0; $i<1000000; $i++) stripos($mystring, $findme) !== false; $time_needed_stripos = getmicrotime() - $time_start; echo 'stripos() !== false: ', round( $time_needed_stripos , 8 ) . PHP_EOL; echo PHP_EOL; echo 'time_needed_stristr - time_needed_strstr: ', round( $time_needed_stristr - $time_needed_strstr , 8) . PHP_EOL; echo 'time_needed_stripos - time_needed_strpos: ', round( $time_needed_stripos - $time_needed_strpos , 8) . PHP_EOL; echo PHP_EOL; echo 'time_needed_strstr - time_needed_strpos: ', round( $time_needed_strstr - $time_needed_strpos , 8) . PHP_EOL; echo 'time_needed_stristr - time_needed_stripos: ', round( $time_needed_stristr - $time_needed_stripos , 8) . PHP_EOL; echo '</pre>'; ?>
And here is the first conclusion that shows that strpos() is the winner :
strstr & strpos TEST: strstr(): 2.39144707 stristr(): 3.65685797 strpos() !== false: 2.39055395 stripos() !== false: 3.54681897 time_needed_stristr - time_needed_strstr: 1.2654109 time_needed_stripos - time_needed_strpos: 1.15626502 time_needed_strstr - time_needed_strpos: 0.00089312 time_needed_stristr - time_needed_stripos: 0.110039
The next one is similar to the first result ( strpos() wins again):
strstr & strpos TEST: strstr(): 2.39969015 stristr(): 3.60772395 strpos() !== false: 2.38610101 stripos() !== false: 3.34951186 time_needed_stristr - time_needed_strstr: 1.2080338 time_needed_stripos - time_needed_strpos: 0.96341085 time_needed_strstr - time_needed_strpos: 0.01358914 time_needed_stristr - time_needed_stripos: 0.25821209
Below is another one, which is more interesting, because in this case the winner is: strstr() :
strstr & strpos TEST: strstr(): 2.35499191 stristr(): 3.60589004 strpos() !== false: 2.37646604 stripos() !== false: 3.51773095 time_needed_stristr - time_needed_strstr: 1.25089812 time_needed_stripos - time_needed_strpos: 1.14126492 time_needed_strstr - time_needed_strpos: -0.02147412 time_needed_stristr - time_needed_stripos: 0.08815908
This means that it can really depend on “environmental circumstances” , which are sometimes difficult to influence, and can change the result of “microoptimization tasks” as follows if you just check if the string exists in another or not.
BUT I think that in most cases strpos() is a winner compared to strstr() .
I hope this test was useful for someone.