易截截图软件、单文件、免安装、纯绿色、仅160KB

PHP中的stristr(),strstr(),strpos()速度比较


PHP中的stristr(),strstr(),strpos()速度比较

测速代码:

<?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()
第一次:2.74142408371
第二次:2.52075314522
第三次:2.52766990662

strstr()
第一次:1.43941402435
第二次:1.44914388657
第三次:1.51285290718

strpos()
第一次:1.42109084129
第二次:1.40254187584
第三次:1.38609910011
----------------------------------
可以看出,stristr在进行判断某一字符(串)是否存在于另一字符(串)时候,速度明显慢于另外两个。。
stristr对大小写不敏感的
strstr对大小写敏感
strpos不能判断是否有特殊字符(包括中文字符)

呵呵,以后用的时候记得选择好啦。。


相关文档:

linux下用phpize给PHP动态添加扩展

使用php的常见问题是:编译php时忘记添加某扩展,后来想添加扩展,但是因为安装php后又装了一些东西如PEAR等,不想删除目录重装,别说,php还真有这样的功能。
  我没有在手册中看到。
  如我想增加bcmath支持,这是一个支持大整数计算的扩展。windows自带而且内置,linux“本类函数仅在 PHP 编译时配置了 --ena ......

不错的php分布类

<?php
function genpage(&$sql,$page_size=10)
{
      global $pages,$sums,$eachpage,$page; //总页数,总记录,每页数,当前页
      $page = $_GET["page"];
   if($page ==0)$page =1;
      $eachpage = $page_s ......

php删除文件和整个文件夹

function delfile($dir)
{
if (is_dir($dir))
{
$dh=opendir($dir);
while (false !== ( $file = readdir ($dh)))
{
if($file!="." && $file!="..")
{
$fullpath=$dir."/".$file;
if(!is_dir($fullpath))
{
unlink($fullpath);
} ......

php缓存心得

SQL查询缓存
适合读者
本教程适合于那些对缓存SQL查询以减少数据库连接与执行的负载、提高脚本性能感兴趣的PHP程序员。
概述
许多站点使用数据库作为站点数据存储的容器。数据库包含了产器信息、目录结构、文章或者留言本,有些数据很可能是完全静态的,这些将会从一个缓存系统中得到的极大好处。
这样一个系统通过把S ......

在Apache中支持PHP的配置参数

打开 httpd.conf 文件 加入以下配置
以php模块配置apache2.2.x 
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL by hooyes
PHPIniDir "D:/php-5.2.6-Win32/"
LoadFile D:/php-5.2.6-Win32/php5ts.dll
LoadFile D:/php-5.2.6-Win32/li ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号