Example
Replace the character "ia" in string with "eo":
<?php echo strtr("Hilla Warld","ia","eo"); ?>
Definition and usage
strtr() FunctionConvert specific characters in a string.
Note: If the lengths of the from and to parameters are different, format them 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 array is used). 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 in which the key name is the original character and the key value is the target character. |
Technical details
Return value: | Returns the converted characters. If the array parameter contains an empty string ("") key name, return FALSE. |
PHP version: | 4+ |
<?php $arr = array("Hello" => "Hi", "world" => "earth"); echo strtr("Hello world",$arr); ?>
<?php echo strtr("Hilla Warld","ia","eo"); ?>
Hello World example 2
<?php $arr = array("Hello" => "Hi", "world" => "earth"); echo strtr("Hello world",$arr); ?>
Hi earth
The above is the detailed content of PHP function strtr() that converts specific characters in a string. For more information, please follow other related articles on the PHP Chinese website!