我一直在谷歌上搜索,也在这里搜索,但可以找到解决方案。我正在使用PHP。我正在读取文本字符串(X509证书的一部分),并将é编码为\ xC3 \ xA9(André=> Andr \ xC3 \ xA9)。
我尝试过MonkeyPhysics's解决方案:
preg_replace("#(\\\x[0-9A-F]{2})#ei", "chr(hexdec('\\1'))", $string);
然后我得到André
我玩过替换部分;
mb_convert_encoding('&#' . hexdec('\\1') . ';', 'ISO-8859-1', 'UTF-8')
(也是to_encoding和from_encoding)
我也看了How to transliterate non-latin scripts?,但没有接近。
当然这应该是标准转换?
答案 0 :(得分:1)
现在在PHP中不推荐使用e
修饰符。您需要使用preg_replace_callback
代替/u
修饰符来处理unicode字符串。
$string = 'His nickname was \xE2\x80\x98the Angel\xE2\x80\x99,
which is kind of a clich\xC3\xA9 in my opinion.';
$repl = preg_replace_callback("#(\\\x[0-9A-F]{2})#ui",
function ($m) { return chr(hexdec($m[1])); }, $string);
His nickname was ‘the Angel’,
which is kind of a cliché in my opinion.