我陷入了如何通过PHP将ISO-8859-3转换为UTF-8字符的问题。正在从MySQL数据库(设置为utf8_unicode_ci)中检索数据。我要转换的字符是ċ,ġ,ħ和ż。 我要求ċ被转换为c ,ġ转换为g ,ħ转换为h ,ż转换为z
任何帮助将不胜感激。
答案 0 :(得分:0)
您可以使用preg_replace一次替换多个字符:
<?php
$str = "I require that ċ is converted c ,ġ is converted g ,ħ is converted h ,ż is converted z";
function _search_replace ($s) {
$search_for = array('/ċ/', '/ġ/', '/ħ/', '/ż/');
$replace_with = array('c', 'g', 'h', 'z');
return preg_replace($search_for, $replace_with, $s);
}
print _search_replace($str);
将输出:
I require that c is converted c ,g is converted g ,h is converted h ,z is converted z