PHP strtr()Functions
Examples
Replace the characters "ia" in the string with "eo":
echo strtr("Hilla Warld","ia","eo");
Run Example »
Definition and Usage
The strtr() function converts specific characters in a string.
Note:If the from and to parameters have different lengths, the result is formatted to the shortest length.
Syntax
strtr(string,from,to)
or
strtr(string,array)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to be converted. |
| from | Required (unless an array is used). Specifies the characters to be changed. |
| to | Required (unless an array is used). Specifies the characters to change to. |
| array | Required (unless from and to are used). An array where the key names are the original characters and the key values are the target characters. |
Technical Details
| Return Value: | Returns the converted string. Ifarraythe parameter contains a key name of an empty string (""), it returns FALSE. |
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
Replace the string "Hello world" with "Hi earth":
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
Run Example »
Other Extensions
PHP String Reference Manual