成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁(yè) ? 技術(shù)教程 ? PHP字符串函數(shù)strtr()的用法
全站頭部文字 我要出現(xiàn)在這里
PHP字符串函數(shù)strtr()的用法 687 2023-12-12   

strtr

(PHP 4, PHP 5)

strtr — 轉(zhuǎn)換指定字符

說(shuō)明

string strtr ( string $str , string $from , string $to ) string strtr ( string $str , array $replace_pairs )

該函數(shù)返回 str 的一個(gè)副本,并將在 from 中指定的字符轉(zhuǎn)換為 to 中相應(yīng)的字符。 比如, $from[$n]中每次的出現(xiàn)都會(huì)被替換為 $to[$n],其中 $n 是兩個(gè)參數(shù)都有效的位移(offset)。

如果 fromto 長(zhǎng)度不相等,那么多余的字符部分將被忽略。 str 的長(zhǎng)度將會(huì)和返回的值一樣。

If given two arguments, the second should be an array in the form array('from' => 'to', ...). The return value is a string where all the occurrences of the array keys have been replaced by the corresponding values. The longest keys will be tried first. Once a substring has been replaced, its new value will not be searched again.

In this case, the keys and the values may have any length, provided that there is no empty key; additionally, the length of the return value may differ from that of str. However, this function will be the most efficient when all the keys have the same size.

參數(shù)

str

待轉(zhuǎn)換的字符串。

from

字符串中與將要被轉(zhuǎn)換的目的字符 to 相對(duì)應(yīng)的源字符。

to

字符串中與將要被轉(zhuǎn)換的字符 from 相對(duì)應(yīng)的目的字符。

replace_pairs

參數(shù) replace_pairs 可以用來(lái)取代 tofrom 參數(shù),因?yàn)樗且? array('from' => 'to', ...) 格式出現(xiàn)的數(shù)組。

返回值

返回轉(zhuǎn)換后的字符串。

如果 replace_pairs 中包含一個(gè)空字符串("")鍵,那么將返回 FALSE。 If the str is not a scalar then it is not typecasted into a string, instead a warning is raised and NULL is returned.

范例

Example #1 strtr() 范例

<?php
$addr = strtr($addr, "???", "aao");
?>

The next example shows the behavior of strtr() when called with only two arguments. Note the preference of the replacements ("h" is not picked because there are longer matches) and how replaced text was not searched again.

Example #2 使用兩個(gè)參數(shù)的 strtr() 范例

<?php
$trans = array("hello" => "hi", "hi" => "hello");
echo strtr("hi all, I said hello", $trans);
?>

以上例程會(huì)輸出:

hello all, I said hi

The two modes of behavior are substantially different. With three arguments, strtr() will replace bytes; with two, it may replace longer substrings.

Example #3 strtr() behavior comparison

<?php
echo strtr("baab", "ab", "01"),"n";

$trans = array("ab" => "01");
echo strtr("baab", $trans);
?>

以上例程會(huì)輸出:

1001
ba01

參見

str_replace() - 子字符串替換 preg_replace() - 執(zhí)行一個(gè)正則表達(dá)式的搜索和替換


主站蜘蛛池模板: 六年级上册英语书电子版翻译| 黑暗女监日本电影完整版叫什么| 插树岭演员表| 一江深情简谱| 日本电影高校教师| 黄视频免费在线播放| 与心有关的成语| 楚门的世界演员表| 王渝萱林教授最经典的三个角色| 简单的公告范文| 黄色网址视频| 所求皆所愿| 电影《kiskisan》在线播放| 北京卫视今晚的电视剧是什么| 罗中立的《父亲》详案| 色女在线| 名星| 谢承均| 《父亲的爱》阅读理解答案| 看黄免费在线| 任港秀| 浙江卫视今日节目表| 消防知识竞赛题库及答案| 老阿姨电视剧在线观看| 守护大电影| 白雪公主在线| 唱这歌| 金珊| 87版七仙女台湾| 在路上 电影| 朴允载| 花守由美里| 速度与激情 电影| 向退休生活游戏正版赚钱入口| 陈慧娴个人资料| 儿子给妈妈过生日,妈妈幸福感言| 寡妇一级毛片视频| 咖啡爱上香草电视剧| 职业探索怎么写| 李慧珍演的电影有哪些| 车震电影|

!!!站長(zhǎng)長(zhǎng)期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長(zhǎng)微信:lxwl520520

站長(zhǎng)QQ:1737366103