PHP strtr() function
Example
Replace the character "ia" in the string with "eo":
<?php echo strtr("Hilla Warld","ia","eo"); ?>
Definition and Usage
The strtr() function converts specific characters in a string.
Note:If from and to If the length of the parameters is different, they will be 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 using array). Specifies the characters to be changed. |
to | required (unless using array). Specifies the characters to be changed to. |
array | required (unless using from and to). Array, where the key names are the original characters to be changed and the key values are the target characters. |
Technical Details
Return value: |
Returns the converted characters. If array If the parameter contains a key name with an empty string (""), FALSE will be returned. |
PHP Version: | 4+ |
More Examples
Example 1
Replace the string "Hello world" with "Hi earth":
<?php $arr = array("Hello" => "Hi", "world" => "earth"); echo strtr("Hello world",$arr); ?>