1

可能是一个非常简单的问题,但我想知道如何将 utf8 字符解码为可读字符。

例如 :

L'heure suprême

进入

L'heure 至上

我尝试了以下方法:

utf8_encode , utf8_decode And `html_entity_decode($string, ENT_COMPAT, "UTF-8");`

例如,输出从未给我正确的字符

 html_entity_decode($string, ENT_COMPAT, "UTF-8"); returned L'heure suprême

编辑:这是一个愚蠢的问题, html_entity_decode($string, ENT_COMPAT, "ISO-8859-15");成功了

4

1 回答 1

0

为了正确显示结果,您需要告诉接收端使用哪种编码:

header('Content-Type: text/plain; charset=UTF-8');

$string = 'L'heure suprême';
print html_entity_decode($string, ENT_COMPAT, "UTF-8");

没有明确命名字符集编码的输出会引发未定义的行为。今天早些时候,有人推荐了 Joel Spolsky 撰写的一篇关于 Unicode 和字符集的精彩文章。它很适合阅读,我建议您“略读”它。

于 2011-01-25T15:05:38.130 回答