PHP strtr() Function

September 28, 2019
7:33 PM
0

ArrayBeginnerFunctionsPHPString

PHP strtr() Function

The strtr() function translates certain characters in a string.

Note: If the from and to parameters are different in length, both will be formatted to the length of the shortest.

For Example:

<?php
echo strtr("Froficient Sesigners","FS","PD");
?>

So the output will be Proficient Designers

For the Syntax is:

strtr(string,from,to)

(OR)

strtr(string,array)
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

Another Example based on array:

<?php
$arr = array("Deep" => "Proficient", "Sea" => "Designers");
echo strtr("Deep Sea",$arr);
?>

So the output will be Proficient Designers


About Author

Karthikesavan

I'm the founder of Proficient Designers. I'm a full time PHP, Wordpress, Android app and UI/UX developer who is passionate in coding.

Comments & Replies