【发布时间】:2010-11-30 01:50:53
【问题描述】:
我正在为 PHP 寻找兼容 UTF-8 的 strtr。
【问题讨论】:
我正在为 PHP 寻找兼容 UTF-8 的 strtr。
【问题讨论】:
我稍微编辑了 joeforker 的函数以返回使用第二个参数作为 replace_pairs 数组的功能。
【讨论】:
function strtr_utf8($str, $from, $to) {
$keys = array();
$values = array();
preg_match_all('/./u', $from, $keys);
preg_match_all('/./u', $to, $values);
$mapping = array_combine($keys[0], $values[0]);
return strtr($str, $mapping);
}
【讨论】: