Definition and usage
strtr() function converts specific characters in a string.
Syntax
strtr(string,from,to) or
strtr(string,array) Parameter Description
string1 Required. Specifies the string to be converted.
from Required (unless using an array). Specifies the character to be changed.
to Required (unless using an array). Specifies the character to change to.
array required (unless from and to are used). An array where the keys are the original characters and the values are the target characters.
Explanation
If the lengths of from and to are different, format them to the shortest length.
Example
Example 1
Copy code The code is as follows:
echo strtr("Hilla Warld","ia","eo");
?>
Copy the code The code is as follows:
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>
The above introduces the instructions for using the PHP strtr function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.