如何在PHP中正确显示中文字符? [英] How to properly display Chinese characters in PHP?
问题描述
我有这些汉字:
汉字/漢字''test
如果我这样做
echo utf8_encode($chinesevar);
它显示
??/??''test
或者即使我只是做一个简单的
Or even if I just do a simple
echo $chinesevar
它仍然显示一些奇怪的字符...
it still displays some weird characters...
那么我该如何显示这些汉字而不在UTF-8事物..或ini_set UTF-8事物甚至是UTF-8的header()事物中使用< meta>标记呢?>
So how am I going to display these Chinese characters without using the <meta> tag with the UTF-8 thingy .. or the ini_set UTF-8 thing or even the header() thing with UTF-8?
推荐答案
简单:
- 将您的源代码保存为UTF-8
-
输出一个HTTP标头,以向浏览器指定应使用UTF-8解释页面:
- save your source code in UTF-8
output an HTTP header to specify to your browser that it should interpret the page using UTF-8:
header('Content-Type: text/html; charset=utf-8');
完成.
utf8_encode
用于将Latin-1编码的字符串转换为UTF-8.您不需要它.
utf8_encode
is for converting Latin-1 encoded strings to UTF-8. You don't need it.
有关更多详细信息,请参见在Web应用程序中处理Unicode从头到尾.
For more details, see Handling Unicode Front To Back In A Web App.
这篇关于如何在PHP中正确显示中文字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!