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不能判断是否有特殊字符(包括中文字符)
呵呵,以后用的时候记得选择好啦。。
相关文档:
1,Smarty缓存的配置:
$smarty->cache-dir="目录名"; //创建缓存目录名
$smarty->caching=true; //开启缓存,为false的时候缓存无效
$smarty->cache_lifetime=60; //缓存时间,单位是秒
2,Smarty缓存的使用与清除
$marty->d ......
<?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= ......
SQL查询缓存
适合读者
本教程适合于那些对缓存SQL查询以减少数据库连接与执行的负载、提高脚本性能感兴趣的PHP程序员。
概述
许多站点使用数据库作为站点数据存储的容器。数据库包含了产器信息、目录结构、文章或者留言本,有些数据很可能是完全静态的,这些将会从一个缓存系统中得到的极大好处。
这样一个系统通过把S ......
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") ......
PHP 向它运行的任何脚本提供了大量的预定义常量
。不过很多常量都是由不同的扩展库定义的,只有在加载了这些扩展库时才会出现,或者动态加载后,或者在编译时已经包括进去了。
有五个魔术常量根据它们使用的位置而改变。例如 __LINE__
的值就依赖于它在脚本中所处的行来决定。这些特殊的常量不区分大小写,如下:
表 13 ......