PHP 将 ISO-8859-3 字符转换为 UTF-8

标签 php mysql

我陷入了如何通过 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/

相关文章:

mysql - LEFT JOIN 显示重复匹配项

mysql - 比使用大量 LIKE 查询 mysql 更高效

php - 从 PHP 站点进行 Websphere 单点登录?

php - 失败的登录尝试记录到数据库

javascript - 在页面加载时运行 JS 函数

php - 即使密码是服务器生成的,也要散列密码?

php - 执行mysqli提取以显示网页的标题和标题时发生错误

php - 如何在回调函数中包含变量?

php - 将json数组插入mysql数据库

mysql - 将 MySQL 数据库从 Linux 迁移到 Mac?