PHP strtr

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : strtr() function

Description

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 :

  1. $string = 'Good Marning....';  

  2. echo  strtr($string, 'Ma', 'mo');  

  3. ?>  

Output :

Good morning....