将KOI8-R转换为UTF8

4

我需要将一个KOI8-R编码的字符串转换为纯UTF8格式。


请注意,仅当您100%确定原始编码时,转换编码才能保证有效。 - Daniel Vandersluis
2个回答

6
你可以使用 mb_convert_encoding 函数:
$output = mb_convert_encoding($input, 'UTF-8', 'KOI8-R');

3
$output = iconv('KOI8-R', 'UTF-8', $input);

也起作用了 :)

还有一种选择是它可以删除损坏或无法识别的字符

iconv("KOI8-R", "UTF-8//IGNORE", $text)

但是你需要安装iconv。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接