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中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 ......
文件check.php
<?php
//生成验证码图片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//播下一个生成随机数字的种子,以方便下面随机数生成的使用
session_start();//将随机数存入session中
$_SESSION['authnum']="";
$im = imagecreate(62,20); //制定图片背景大小
$black = ImageC ......
<?php
/*
* Created on 2009-10-28
* 分子如梦o(╯□╰)o
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
interface pusb{
function verson();
  ......
在为用户提供动态内容方面,PHP和MySQL是一个强大的组合。这些年来,这两项产品已经跨越了它们最初的应用舞台,现在,一些世界上最繁忙的网站也在应用它们。虽然它们当初都是开源软件,只能在UNIX/Linux上运行,但经过相当一段时期的发展,它们已能在Windows平台上运行。
在本文中,我将逐步为你们说明如何在Windows环境中 ......
<?php
class useful{
/*
* 常用函数类
* 作 者:多菜鸟
* 联系邮箱:kingerq AT msn DOT com
* 创建时间:2005-07-18
* 来源:http://blog.csdn.net/kingerq
*/
/*
* 功能:格式化数字,以标准MONEY格式输出
......