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

PHP中strtr和str_replace比较

首先这2个函数都是具有替换字符功能的。但是strtr比str_replace性能上要块4倍。具体情况请看如下分解:
首先是strtr函数:
实例1:当
以下为引用的内容:
<?php
//这个时候输出的为baicai而不是bai123cai,因为str("pao")<strlen("bai123")
echo strtr("paocai!","pao","bai123");
?>
实例2:当被替换的值长度小于被替换目标的时候
以下为引用的内容:
<?php
//这个时候输出的为laocai而不是lacai,因为str("pao")>strlen("la")
 
echo strtr("paocai!","pao","la");
 
?>
实例3:支持数组替换
以下为引用的内容:
<?php
$Arr=array('ao'=>'oa','ai'=>'ia');
echo strtr("paocai!",$Arr); //这个时候输出的为poacia
?>
其次是str_replace:
以下为引用的内容:
<?php
echo str_replace("you","paocai","I love you!"); //会输出I love paocai!
?>
总结:strtr他是跟字符长度有关系的,但是str_replace就没有关系,估计在运行步骤的时候会读取字符串长度所以才会比strtr慢很多。


相关文档:

php实现一个日历类

<?php
 date_default_timezone_set("Etc/GMT-8");
 header("content-type:text/html; charset=utf-8");
 /**
  * 自己定义的一个生成日历的类
  * @author 张伟灿<yuanfen860913@163.com>
  * @version 1.0.0
  *
  */
 class myCalendar
 {
  ......

php中substr的用法详解

php中substr的用法详解
php.net中关于substr的说明很简单:
start
If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so for ......

PHP多语言系统的一种实现方式[转]


在网站设计中我们经常会遇到需要多语言支持的情况。多语言系统按照支持的方式一般可分为两种:
1.支持多语言,但不支持多种语言的同时存在,也就是说要么是中文要么是英文或者其他,这在一些需要国际化支持的网页系统中经常用来,以便方便用户本地化。 2.支持多语言并可同时浏览不同语言版本的网页。今天我想讨 ......

php生成验证码图片代码

文件check.php
<?php
//生成验证码图片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//播下一个生成随机数字的种子,以方便下面随机数生成的使用
session_start();//将随机数存入session中
$_SESSION['authnum']="";
$im = imagecreate(62,20); //制定图片背景大小
$black = ImageC ......

php常用函数2

文件读取函式
   //文件读取函式
   function PHP_Read($file_name) {
   $fd=fopen($file_name,r);
   while($bufline=fgets($fd, 4096)){
   $buf.=$bufline;
    }
   fclose($fd);
   return $buf;
    }
& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号