Current Location: Home> Function Categories> strtr

strtr

Translate characters or replace substrings - convert specified characters
Name:strtr
Category:String
Programming Language:php
One-line Description:Converts specific characters in a string.

Definition and usage

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.

Example

Example 1

Replace the character "ia" in the string with "eo":

 <?php
echo strtr ( "Hilla Warld" , "ia" , "eo" ) ;
?>

Try it yourself

Example 2

Replace the string "Hello world" with "Hi earth":

 <?php
$arr = array ( "Hello" => "Hi" , "world" => "earth" ) ;
echo strtr ( "Hello world" , $arr ) ;
?>

Try it yourself

grammar

 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.
Similar Functions
Popular Articles