英[strɪŋ] 美[strɪŋ]

n.String; rope, belt; thread, plant fiber; [Computer Science] String

vt. Winding, tuning; To line up in a line or a series; to tie, tie or hang with a thread; to extend or extend

Third person singular: strings Plural: strings Present participle: stringing Past tense: strung Past participle: strung

php strtr() function syntax

Function:Convert certain characters in the string

Syntax: strtr(string,from,to)or strtr(string,array)

Parameters:

##ParametersDescription stringRequired. Specifies the string to be converted. fromRequired (unless using an array). Specifies the character to be changed. toRequired (unless using an array). Specifies the character to change to. arrayRequired (unless from and to are used). An array in which the key name is the original character of the change and the key value is the target character of the change.

#Description: Convert specific characters in the string. If the lengths of the from and to parameters are different, they will be formatted to the shortest length.

php strtr() function example

<?php
//将字符串中的"i,a"替换成"e.o"
echo strtr("Hilla php.cn","ia","eo");
echo "<br>";
//替换数组中的元素
$arr = array("Hello" => "Hi", "world" => "php.cn");
echo strtr("Hello world",$arr);
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

Hello php.cn
Hi php.cn


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

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

Hi php.cn