w3resource

PHP: strtr() function

PHP: Translate characters or replace substrings

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

Version:

(PHP 4 and above)

Syntax:

strtr(string_name, from_string, to_string) 

Parameters:

Name Description Required /
Optional
Type
string_name The string to be translated. Required String
from_string Contains characters to be translated. Required String
to_string Contains characters to be translated with. Required String

Another Syntax:

strtr(string_namer, translating_array)

Parameters:

Name Description Required /
Optional
Type
string_name The string to be translated Required String
translating_array Contains key value pairs. If values of the array elements are matched in the input string, then those characters in the input string are replaced with the corresponding keys of those values. Required Array

Return value:

Returns the translated string.

Value Type: String.

Pictorial Presentation

string_strtr

Example:

<?php
$string = 'Good Marning....';
echo  strtr($string, 'Ma', 'mo');
?>

Output:

Good morning....

View the example in the browser

See also

PHP Function Reference

Previous: strtoupper
Next: substr_compare



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/strtr.php