X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP strtr() Function

PHP String Reference PHP String Reference

Example

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

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

Run example »

Definition and Usage

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.


Syntax

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

Technical Details

Return Value: Returns the translated string.
If the array parameter contains a key which is an empty string (""), it will return FALSE.
PHP Version: 4+


More Examples

Example 1

Replace the string "Hello world" with "Hi earth":

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

Run example »


PHP String Reference PHP String Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook