Replace the characters "ia" in the string with "eo":
<?php echo strtr ( " Hilla Warld " , " ia " , " eo " ) ; ?>The strtr() function converts specific characters in a string.
Note: If the lengths of the from and to parameters are different, format to the shortest length.
strtr( string,from,to )
or
strtr( string,array )
parameter | describe |
---|---|
string | Required. Specifies the string to be converted. |
from | Required (unless using an array). 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. |
Return value: | Returns the converted characters. If the array parameter contains an empty string ("") key name, return FALSE. |
---|---|
PHP version: | 4+ |
Replace the string "Hello world" with "Hi earth":
<?php $arr = array ( " Hello " => " Hi " , " world " => " earth " ) ; echo strtr ( " Hello world " , $arr ) ; ?>