易截截图软件、单文件、免安装、纯绿色、仅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的18个基础例程

 
如何创建我们的第一个PHP页面呢?非常简单的!选择我们使用的一个最好的设计工具,当然你也可以 只使用记事本。创建之后记得要保存为扩展名为PHP的文件,然后传到我们的服务器
上。
  在编写PHP程序之前通常我们需要配置我们的环境,也就是说服务器
要支持PHP才能行啊
  一、PHP的基本结构:
  使用Incl ......

不错的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对zip文件解压和压缩

<?php
/**
* @author wyt
*
*/
class zip {
private $_zipObj=null;
private $_zipfcArr=array();
private $_basePath=null;
private $_zipName;
/**
* init
* @param zip文件名称 $zipName
*/
function __construct($zipName){
$this->_zipName=$zipName;
$this->_zipObj= ......

php ajax debug method make log in a text file

log into file
//
ob_start();
echo "<pre>";
print_r($data);
echo "</pre>";
$a=ob_get_contents();
//DAL::remove("insert into mytest(vvv) values('$a')");
$filename = "file.txt";
$file = fopen($filename, "w") ......

HTTPService与PHP通信

在Flex中有2个HTTPService类,它们的完整继承路径分别是mx.rpc.http和mx.rpc.http.mxml,可以看出mx.rpc.http.mxml是mx.rpc.http的子类。mx.rpc.http.mxml中的httpService主要是为了MXML标签中使用HTTPService而设的。mx.rpc.http是在使用as脚本进行操作时使用。当调用 HTTPService 对象的 send() 方法时,将发出对指定 URL ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号