定义和用法
strtr() 函数转换字符串中特定的字符。
语法
strtr(string,from,to)或者
strtr(string,array)参数 描述
string1 必需。规定要转换的字符串。
from 必需(除非使用数组)。规定要改变的字符。
to 必需(除非使用数组)。规定要改变为的字符。
array 必需(除非使用 from 和 to)。一个数组,其中的键是原始字符,值是目标字符。
说明
如果 from 和 to 的长度不同,则格式化为最短的长度。
例子
例子 1
echo strtr("Hilla Warld","ia","eo");
?>
输出:
Hello World例子 2
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>
输出:
Hi earth
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn