这是背景。在下面的代码中,我试图使用php、ajax和jquery从mysql服务器检索unicode字符。
$.post("test.php",{tableName: A_table}, function(data)
{
$.each($(data), function(key, value)
{
display data into an UL List and not display weird unicode characters, like 00101C
}
});
基于上面的代码,我如何获得要显示的unicode字符。
您应该强制响应的charset
标头为UTF-8
(或其他适合您需要的字符集),或者您可以预先使用mb_convert_encoding 在服务器端转换所有unicode字符
示例(取自手册页)
<?php
$text = "A strange string to pass, maybe with some ø, æ, å characters.";
foreach(mb_list_encodings() as $chr){
echo mb_convert_encoding($text, 'UTF-8', $chr)." : ".$chr."<br>";
}
?>