Speed Code:
<?php
function Getmicrotime ()
{
List ($usec, $sec) = Explode ("", Microtime ());
return (float) $usec + (float) $sec);
}
$time _start = Getmicrotime ();
$string = "Xxxddxx";
$find = "D";
for ($i =0; $i <300000; $i + +)
{
if (Stristr ($string, $find))//if (Strstr ($string, $find)) or if (Strpos ($string, $find))
{}
}
$time _end = Getmicrotime ();
echo $time _end-$time _start;
?>
[/php]
Stristr ()
First time: 2.74142408371
Second time: 2.52075314522
Third time: 2.52766990662
Strstr ()
First time: 1.43941402435
Second time: 1.44914388657
Third time: 1.51285290718
Strpos ()
First time: 1.42109084129
Second time: 1.40254187584
Third time: 1.38609910011
----------------------------------
As you can see, STRISTR is significantly slower than the other two when judging whether a character (string) exists in another character (string).
Stristr is not sensitive to case
Strstr sensitive to case sensitivity
Strpos cannot determine if there are special characters (including Chinese characters)
Oh, after the use of the time to remember to choose well.
Stristr (), Strstr (), Strpos () speed comparison in PHP