strtr
Translate characters or replace substrings - convert specified characters
strtr()
function converts specific characters in a string.
Note: If the length of the from and to parameters is different, it will be formatted to the shortest length.
Replace the character "ia" in the string with "eo":
<?php echo strtr ( "Hilla Warld" , "ia" , "eo" ) ; ?>
Try it yourself
Replace the string "Hello world" with "Hi earth":
<?php $arr = array ( "Hello" => "Hi" , "world" => "earth" ) ; echo strtr ( "Hello world" , $arr ) ; ?>
Try it yourself
strtr ( string , from , to )
or:
strtr ( string , array )
parameter | describe |
---|---|
string | Required. Specifies the string to be converted. |
from | Required (unless array is used). Specifies the characters to be changed. |
to | Required (unless array is used). Specifies the characters to be changed to. |
array | Required (unless from and to ). Array where the key name is the changed original character and the key value is the changed target character. |