我陷入了如何通过 PHP 将 ISO-8859-3 转换为 UTF-8 字符的困境。正在从 MySQL 数据库(设置为 utf8_unicode_ci)检索数据。我试图转换的字符是 ċ、ġ、ħ 和 ż。 我要求将 ċ 转换为 c ,ġ 转换为 g ,ħ 转换为 h ,ż 转换为 z
如有任何帮助,我们将不胜感激。
最佳答案
您可以使用 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
关于PHP 将 ISO-8859-3 字符转换为 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52567079/