what is the syntax of the STRTR() function in php?
strtr(string,from,to)
Parameter | Description |
---|---|
string | Required. Specifies the string to translate |
from | Required (unless array is used). Specifies what characters to change |
to | Required (unless array is used). Specifies what characters to change into |
array | Required (unless to and from is used). An array containing what to change from as key, and what to change to as value |
examples of the STRTR() function
Example 1. In this example, we replace the characters “ia” in the string with “eo”.
<?php
echo strtr("Hilla Warld","ia","eo");
?>
Example 1. In this example, we replace the string “Hello world” with “Hi earth”.
<?php
$arr = array("Hello" => "Hi", "world" => "earth");
echo strtr("Hello world",$arr);
?>