PHP strtr() 函数

PHP 教程 · 2019-01-30 13:14:38

实例

把字符串中的字符 "ia" 替换成 "eo":

<?php echo strtr("Hilla Warld","ia","eo"); ?>

定义和用法

strtr() 函数转换字符串中特定的字符。

注释:如果 from 和 to 参数的长度不同,则格式化为最短的长度。

语法


strtr(string,from,to)

或者


strtr(string,array)


参数 描述
string 必需。规定要转换的字符串。
from 必需(除非使用数组)。规定要改变的字符。
to 必需(除非使用数组)。规定要改变为的字符。
array 必需(除非使用 from 和 to)。一个数组,其中的键名是原始字符,键值是目标字符。

技术细节

返回值: 返回已转换的字符。
如果 array 参数包含一个空字符串("")的键名,则返回 FALSE。
PHP 版本: 4+

更多实例

实例 1

把字符串 "Hello world" 替换成 "Hi earth":

<?php $arr = array("Hello" => "Hi", "world" => "earth"); echo strtr("Hello world",$arr); ?>

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

New Dark Age

New Dark Age

James Bridle / Verso Books / 2018-7-17 / GBP 16.99

As the world around us increases in technological complexity, our understanding of it diminishes. Underlying this trend is a single idea: the belief that our existence is understandable through comput......一起来看看 《New Dark Age》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具