易截截图软件、单文件、免安装、纯绿色、仅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不能判断是否有特殊字符(包括中文字符)

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


相关文档:

一php大马,值得研究

<?php
#--Config--#
$login_password= '123456'; //这是密码
#----------#
error_reporting(E_ALL);
set_time_limit(0);
ini_set("max_execution_time","0");
ini_set("memory_limit","9999M");
set_magic_quotes_runtime(0);
if(!isset($_SERVER))$_SERVER = &$HTTP_SERVER_VARS;
if(!isset($_POST))$_PO ......

php中smarty模版引擎中的缓存应用!

1,Smarty缓存的配置:
   $smarty->cache-dir="目录名";   //创建缓存目录名
   $smarty->caching=true;   //开启缓存,为false的时候缓存无效
   $smarty->cache_lifetime=60; //缓存时间,单位是秒
2,Smarty缓存的使用与清除
   $marty->d ......

php动态生成表格的合并

<?php
$link=mysql_connect("localhost","root","root");
$db=mysql_select_db("bustest",$link);
$sql1="select name from info group by name order by id asc";
print("<table border='1'>");
$res1=mysql_query($sql1);
while($row1=mysql_fetch_array($res1)){
$name=$row1["name"];
$sql2="select i ......

php分页

<?php
//分页
$link=mysql_connect("localhost","root","root");
$db=mysql_select_db("bustest",$link);
$res=mysql_query("select * from info");
//一共多少条
$count=mysql_num_rows($res);
//每页5条信息
$perpage=5;
//一共多少页
$pagecount=ceil($count/$perpage);
//传过来的页数
$pagenum=$_REQUE ......

win下Apache mysql PHP配置

1、HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\MySQL
目录删除
2、HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Services\Eventlog\Application\MySQL
目录删除
3、HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MySQL
目录删除 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号