PHP strtr() Function


The strtr() function is used to replace a certain characters in a string.

Syntax
strtr(string,from,to) or (string,array)
Parameters
  • String - (Required) Specify the string to replace.
  • from - (Required) Specify the which character to change.
  • from - (Required) Specify the which character to change into.
  • array - (Required) Array is passed as the parameter when we want to change any particular substring. .
Example
<?php
    echo strtr("Good Morning","oo","uu");
?>

Output

Guud Murning.
Example
<?php
    $arr = array("Good" => "Hi Good ", "morning" => "evening");
    echo strtr("Good morning",$arr);
?>

Output

Hi Good evening

Prev Next