FtD*_*Xw6 2 php string performance transformation ansi
我很好奇进行字符串转换的最高效的方法是什么。给定一个输入字符串和一组翻译,一般来说哪种方法最有效?我目前使用strtr(),但已经使用str_replace()数组等测试了各种循环方法。该strtr()方法在我的系统上进行了最快的基准测试,具体取决于翻译,但我很好奇是否有我还没有想到的更快的方法。
如果相关的话,我的特定用例涉及将 2 字节字符串转换为终端的 ANSI 颜色序列。例子:
// In practice, the number of translations is much greater than one...
$out = strtr("|rThis should be red", array('|r' => "\033[31m"));
Run Code Online (Sandbox Code Playgroud)