我有几个 PHP在 HTML 中回显各种内容的页面页面代码如下。
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
但是,当我使用 W3C validator 进行验证时它提出了:
The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the element (utf-8).
我对 PHP 很陌生,我想知道是否可以并且应该更改 PHP 文件的标题以匹配 HTML 文件。
最佳答案
使用 header
修改HTTP头:
header('Content-Type: text/html; charset=utf-8');
注意在任何输出发送到客户端之前调用此函数。否则 header 也已发送,您显然无法再更改它。您可以通过 headers_sent
进行检查.见 manual page of header
了解更多信息。
关于php - 如何使用在 W3C 验证器中有效的 PHP 将 HTTP header 设置为 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4279282/