(一)strtr是字符替换函数
(1)单个字符替换:
<?php echo strtr("abba", "ab", "10")," "; echo strtr("baab", "ab", "01")," "; ?>
输出结果为:
(2)字符串对应替换:
<?php $trans = array("ab" => "10"); echo strtr("abba", $trans), " "; ?>
输出结果为:
(二)str_replace替换函数,等同于strtr用数组替换:
<?php echo str_replace("ab", "10", "abba"), " "; ?>
输出结果为: