Home > Backend Development > PHP Tutorial > PHP strtr function usage instructions

PHP strtr function usage instructions

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:39:19
Original
973 people have browsed it

Definition and usage
strtr() function converts specific characters in a string.
Syntax
strtr(string,from,to) or
strtr(string,array) Parameter Description
string1 Required. Specifies the string to be converted.
from Required (unless using an array). Specifies the character to be changed.
to Required (unless using an array). Specifies the character to change to.
array required (unless from and to are used). An array where the keys are the original characters and the values ​​are the target characters.
Explanation
If the lengths of from and to are different, format them to the shortest length.
Example
Example 1

Copy code The code is as follows:


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


Output:
Hello World Example 2

Copy the code The code is as follows:


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


Output:
Hi earth

The above introduces the instructions for using the PHP strtr function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template