PHP中的strtr()函数

strstr()用于转换的字符或替换字符串。

语法

strstr(str, from, to)
or
strstr(str, arr)

参数

  • str-要翻译的字符串

  • -要更改的字符。如果未使用数组,则为必需参数。

  • -要更改为的字符。如果未使用数组,则为必需参数。

  • arr-包含从键更改为什么以及从值更改为什么的数组

返回

strstr()函数返回翻译后的字符串。

示例

以下是一个例子-

<?php
   $mystr = "kom lan" ; 
   $str1 = "koml"; 
   $str2 = "tomh";
   echo strtr($mystr, $str1, $str2);
?>

输出结果

tom han