strtr() 函数翻译字符串中的某些字符。
笔记:如果 from 和 to 参数的长度不同,则两者都将被格式化为最短的长度。
strtr(
string,from,to)
或者
strtr(
string,array)
Parameter | Description |
---|---|
string | Required. Specifies the string to translate |
from | Required (unless array is used). Specifies what characters to change |
to | Required (unless array is used). Specifies what characters to change into |
array | Required (unless to and from is used). An array containing what to change from as key, and what to change to as value |
返回值: | 返回翻译后的字符串。 如果数组参数包含一个空字符串("")的键,它将返回FALSE。 |
---|---|
PHP 版本: | 4+ |
将字符串 "Hello world" 替换为 "Hi earth":
<?php
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!