``` --- ## Definition and"> ``` --- ## Definition and" />
Easy Tutorial
❮ Func Mysqli Get Connection Stats Func Array Filter ❯

PHP strtr() Function

PHP String Reference Manual

Example

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

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

Definition and Usage

The strtr() function converts specific characters in a string.

Note: If the lengths of the from and to parameters are different, they are truncated to the length of the shortest one.


Syntax

Alternatively:

Parameter Description
string Required. Specifies the string to be converted.
from Required (unless using an array). Specifies the character(s) to be replaced.
to Required (unless using an array). Specifies the character(s) to replace with.
array Required (unless using from and to). An array where the keys are the original characters and the values are the target characters.

Technical Details

Return Value: Returns the converted string. <br>Returns FALSE if the array parameter contains an empty string ("") as a key.
PHP Version: 4+
--- ---

More Examples

Example 1

Replace "Hello world" with "Hi earth":

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

PHP String Reference Manual

❮ Func Mysqli Get Connection Stats Func Array Filter ❯