加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP strtr() 函数使用说明

发布时间:2020-12-13 05:29:12 所属栏目:PHP教程 来源:网络整理
导读:定义和用法 strtr() 函数转换字符串中特定的字符。 语法 strtr(string,from,to)或者 strtr(string,array)参数 描述 string1 必需。规定要转换的字符串。 from 必需(除非使用数组)。规定要改变的字符。 to 必需(除非使用数组)。规定要改变为的字符。 arra

定义和用法
strtr() 函数转换字符串中特定的字符。
语法
strtr(string,from,to)或者
strtr(string,array)参数 描述
string1 必需。规定要转换的字符串。
from 必需(除非使用数组)。规定要改变的字符。
to 必需(除非使用数组)。规定要改变为的字符。
array 必需(除非使用 from 和 to)。一个数组,其中的键是原始字符,值是目标字符。
说明
如果 from 和 to 的长度不同,则格式化为最短的长度。
例子
例子 1
<div class="codetitle"><a style="CURSOR: pointer" data="5634" class="copybut" id="copybut5634" onclick="doCopy('code5634')"> 代码如下:<div class="codebody" id="code5634">
<?php
echo strtr("Hilla Warld","ia","eo");
?>

输出:
Hello World例子 2
<div class="codetitle"><a style="CURSOR: pointer" data="97348" class="copybut" id="copybut97348" onclick="doCopy('code97348')"> 代码如下:<div class="codebody" id="code97348">
<?php
$arr = array("Hello" => "Hi","world" => "earth");
echo strtr("Hello world",$arr);
?>

输出:
Hi earth

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读