PHP的 strtr 函数, 性能要比 str_replace 函数高, 可以代替 str_replace 来使用
strtr 有两种形式:
string strtr ( string $str , string $from , string $to )
string strtr ( string $str , array $replace_pairs )
当使用第一种的时候, 参数 $from, $to 的字符串长度一定要相同, 否则多余的(不管是$from多还是$to多) 字符被忽略.
比如 $str = 'a-=b' ;
当$from='-=' ,$to='CD',输出'aCDb', 因为'-='与'CD'的长度相同,没有问题.
当$from='-=' ,$to='CDE',输出'aCDb', $to里的'E'被忽略.
当$from='-=' ,$to='C',输出'aC=b', $from里的'='被忽略.
而使用第二种形式, 则没有这个问题, 多余的字条不会忽略.
所以,如果故意用 strtr 函数代替 str_replace, 并且使用了第一种形式, 则一定要注意这个特征, 这可能是一个陷阱.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.