Definitions and usage
The STRTR () function converts a specific character in a string.
Grammar
STRTR (string,from,to) or
STRTR (string,array) parameter description
String1 required. Specify the string to convert.
From required (unless an array is used). Specify the characters to be changed.
To required (unless an array is used). Specify the character to change to.
Array is required (unless using from and to). An array in which the key is the original character and the value is the target character.
Description
If the length of from and to is different, it is formatted to the shortest length.
Example
Example 1
Copy Code code as follows:
<?php
Echo strtr ("Hilla Warld", "ia", "eo");
?>
Output:
Hello World Example 2
Copy Code code as follows:
<?php
$arr = Array ("Hello" => "Hi", "World" => "the Earth");
Echo strtr ("Hello World", $arr);
?>
Output:
Hi Earth