php将iso-8859-3字符转换为utf-8

fivyi3re  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(270)

我被困在如何通过php将iso-8859-3转换成utf-8字符。正在从mysql数据库(设置为utf8\u unicode\u ci)检索数据。我要转换的字符是ċ,ġ,ħ 以及ż. 我需要这个ċ 转换为c,ġ 转换为g,ħ 转换为h,ż 转换为z
任何帮助都将不胜感激。

vcudknz3

vcudknz31#

可以使用preg\u 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

相关问题