我是靠谱客的博主 曾经毛巾,这篇文章主要介绍php strpos 性能,PHP中的stristr(),strstr(),strpos()速度比較,现在分享给大家,希望可以做个参考。

測速代碼:

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()

第一次:2.74142408371

第二次:2.52075314522

第三次:2.52766990662

strstr()

第一次:1.43941402435

第二次:1.44914388657

第三次:1.51285290718

strpos()

第一次:1.42109084129

第二次:1.40254187584

第三次:1.38609910011

----------------------------------

可以看出,stristr在進行判斷某一字符(串)是否存在於另一字符(串)時候,速度明顯慢於另外兩個。。

stristr對大小寫不敏感的

strstr對大小寫敏感

strpos不能判斷是否有特殊字符(包括中文字符)

呵呵,以后用的時候記得選擇好啦。。

最后

以上就是曾经毛巾最近收集整理的关于php strpos 性能,PHP中的stristr(),strstr(),strpos()速度比較的全部内容,更多相关php内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部