php 如何使用 Iconv 将任何可能的格式转换为 UTF-8?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2806677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert any possible format to UTF-8 using Iconv?
提问by Rella
so for example this will turn 1251 into utf-8.
例如,这会将 1251 转换为 utf-8。
$utf8 = iconv('windows-1251', 'utf-8', $ansi);
But how to turn unknown (when it comes to us we do not know yet what format it is) ( in general any ) format (possibly known by Iconv ) to utf-8? (code sample)
但是如何将未知(对我们而言,我们还不知道它是什么格式)(通常是任何)格式(可能被 Iconv 知道)转换为 utf-8?(代码示例)
采纳答案by soulmerge
You cannot translate from an unknown character set, the best you can do is make a guess about the actual charset and use that guess as first parameter - you can use mb_detect_encoding()for that purpose.
您无法从未知字符集进行转换,您能做的最好的事情就是猜测实际的字符集并将该猜测用作第一个参数 - 您可以mb_detect_encoding()为此目的使用。
回答by lalo
I have written an array with the values of the string. You just need to do this:
我已经用字符串的值编写了一个数组。你只需要这样做:
$string = str_replace("?¢a???“","",$string);
$string = str_replace("?¢a???","",$string);
And they are gone!
他们走了!

