Introduction to the use of strtr function in PHP (str_replace)_PHP tutorial

WBOY
Release: 2016-07-21 15:24:25
Original
1112 people have browsed it

strtr has two forms:

string strtr ( string $str , string $from , string $to )
string strtr ( string $str , array $replace_pairs )
When using the first one At this time, the string lengths of the parameters $from and $to must be the same, otherwise the extra characters (whether there are more $from or more $to) will be ignored.

For example, $str = 'a-=b' ;

When $from='-=', $to='CD', output 'aCDb', because '-=' is the same length as 'CD', there is no problem.

When $from='-=', $to='CDE', 'aCDb' is output, and the 'E' in $to is ignored.

When $from='-=', $to=' C', outputs 'aC=b', and the '=' in $from is ignored.

When using the second form, there is no such problem, and the extra entries will not be ignored.

So, if you deliberately use the strtr function instead of str_replace, and use the first form, you must pay attention to this feature, which may be a trap.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324334.htmlTechArticlestrtr has two forms: string strtr ( string $str , string $from , string $to ) string strtr ( string $str , array $replace_pairs ) When using the first method, the characters of parameters $from, $to...
source:php.cn
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