将 Windows-1256 转换为 UTF-8


Convert Windows-1256 to UTF-8

我通过curl获取网页的内容,字符集设置为Windows-1256。

现在我想使用字符集utf8_general_ci将此数据插入 MySQL 数据库。

有什么办法可以做到这一点吗?

你需要iconv()

$utf8 = iconv('windows-1256', 'utf-8', $win1256);

。虽然Supported character sets depend on the iconv implementation of your system.,所以YMMV。

如果您想要一个 100% 安全、无处不在的方法,最简单的办法就是让查找表成为一种使用str_replace()