PHP strtr() function
Example
Replace the character "ia" in the string with "eo":
مول 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, 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 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 changed, and the key value is the target character. |
Technical details
Return value: |
Returns the converted characters. If array If the parameter contains an empty string (""), the function will return 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); مول