English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strtr() Function Usage and Example

PHP String String Functions Manual

The strtr() function is used to convert specified characters.

Syntax

strtr(string, from, to)

Definition and Usage

It is used to convert characters or replace substrings

Return Value

It returns the converted string

Parameter

Serial NumberParameters and Description
1

string

Required. The string to be converted.

2

from

Required. The source character corresponding to the target character to be converted in the string.

3

to

Required (unless using an array). The target character corresponding to the character from to be converted in the string.

4

array

Required (unless using from and to). An array where the key name is the original character and the value is the target character.

Online Example

Try the following example, replace the character "ia" in the string with "eo":

<?php
   //Replace the character "ia" in the string with "eo"
   echo strtr("Hilla Warld", "ia", "eo");
   
   echo '<br>';
   //Convert phonetic characters äåö to aao
   echo strtr("Paäåö", "äåö", "aao");
   
?>
Test and see‹/›

Output Result

Hello World
Paaao

PHP String String Functions Manual