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 the string.
Note:If from and to If the length of the parameters is different, it 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 character to be changed. |
to | required (unless using array). Specifies the character to be changed to. |
array | required (unless using from and to)。Array, where the key name is the original character to be changed, and the key value is the target character. |
Technical Details
Return Value: |
Returns the converted characters. If array If the key name contains 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); ?>