使用PHP将HTTP标头设置为UTF-8 [英] Set HTTP header to UTF-8 using PHP
问题描述
我有几个 PHP 页面,它们将各种各样的内容反映到 HTML 页面。
< meta http-equiv =Content-typecontent =text / html; charset = utf-8/>
然而,当我使用它提供了W3C验证器:
lockquote
指定的字符编码HTTP header(iso-8859-1)与元素(utf-8)中的值不同。
我很新到PHP,我想知道是否可以并且应该改变PHP文件的头文件以匹配HTML文件。
使用标题
修改HTTP标题: header('Content-Type:text / html; charset = utf-8');
请注意在任何输出发送到客户端之前调用此函数。否则标题也被发送了,你显然不能再改变它了。您可以使用 headers_sent
进行检查。有关更多信息,请参见手册页标题
。
I have several PHP pages echoing out various things into HTML pages with the following code.
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
However, when I validate using the W3C validator it comes up with:
The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the element (utf-8).
I am quite new to PHP, and I was wondering if I could and should change the header for the PHP files to match the HTML files.
Use header
to modify the HTTP header:
header('Content-Type: text/html; charset=utf-8');
Note to call this function before any output has been sent to the client. Otherwise the header has been sent too and you obviously can’t change it any more. You can check that with headers_sent
. See the manual page of header
for more information.
这篇关于使用PHP将HTTP标头设置为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!