Home >>PHP String Functions >PHP strtr() Function
PHP strtr() function is used to replace any certain characters or substring in a given input string with a given string of characters.It is case sensitive. If the to and from parameters are different in length, both will be formatted to the length of the shortest one.
Syntax:
strtr($string, $from, $to);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter defines the string to translate. |
from | This is a required parameter. This parameter defines what characters to change. |
to | This is a required parameter. This parameter defines what characters to change into. |
Here is an example of strtr() function in PHP:
<html> <body> <?php echo strtr("Hallk Evarykna..","ak","eo"); ?> </body> </html>
Here is an another example of strtr() function in PHP:
<html> <body> <?php $str = "Hello Guys!! I am Abhi.."; $arr = array("Hello" => "Hey", "Abhi" => "Jerry"); echo "Input String: ".$str; echo "<br> <br>"; echo "Translated String: ".strtr($str,$arr); ?> </body> </html>