Makes multiple replacements in a string.
There are two different ways of using this function. When used with three string parameters, this function can be used to replace single characters with other single characters. The from string contains the characters that should be replaced, and the to string lists their replacements A new string with the replacements made is returned.
strtr() can also be used to replace sequences of characters. In this case the from and to strings are replaced with a single associative array with the search terms as keys and the replacements as values.
<?php
$s = "Pizza: $12, Spaghetti: $6, Hamburger: £5";
print "$s<br>";
print strtr($s, "\$£", "£€");
?>
Pizza: $12, Spaghetti: $6, Hamburger: £5
Pizza: £12, Spaghetti: £6, Hamburger: €5
This code replaces dollar signs with pound signs, and pound signs with euro signs.