strtr
(PHP3 , PHP4)
strtr --- 转换某些字元
语法 :
string strtr
(string str, string from, string to)说明 :
此函数运作在参数 str上,将参数 from中所有出现的各个字元转换成参数 to相对应的字元,并且传回结果。
如果参数 from和 to的长度不同时,这二个参数多余的字元将会被忽略。
Example :
<?php
$addr = strtr($addr, "麧?, "aao");
?>
呼叫 strtr( )可以只有二个参数,如果只有二个参数,那么它的运作将会有新的方式 : 参数 from必定是个包含字符串 => 字符串对的数组,这将会在原来的字符串中取代。strtr( )将会寻找首先可能的比对,并且不会试着去取代先前已经处理过的字符串。
Example :
<?php
$trans = array ("hello" => "hi", "hi" => "hello");
echo strtr("hi all, I said hello", $trans) . "\n";
?>
这将会显示出 : "hello all, I said hi"。
注意 : 二个参数的特性是新增在PHP 4.0
参考 : ereg_replace( )