差异元和PHP头 [英] Difference meta and PHP header
问题描述
这两者有什么区别,我应该同时使用吗?我希望我的网站能够完全使用UTF-8。
在PHP中:
<?php
header(Content-Type:text / html; charset = utf-8);
?>
和HTML中的元标记:
< meta charset =utf-8>
HTTP Content-Type
header 应始终设置,这是浏览器确定它处理的文档类型的主要来源。只有当这个头文件丢失时,浏览器才会尝试找到一个HTML元标记,它为它提供与后备相同的信息。 因为您可以将HTML文档保存到磁盘,在这种情况下,HTTP标头将会在以后需要它的任何人使用。
您可以找到浏览器如何确定文档字符集的确切规则: http://www.w3.org/TR/html5/syntax.html#determining-the-character-encoding
What is the difference between these two and should I use both ? I want my website to be fully UTF-8.
In PHP:
<?php
header("Content-Type: text/html; charset=utf-8");
?>
And the meta tag in HTML:
<meta charset="utf-8">
The HTTP Content-Type
header should always be set, it's the primary source for the browser to figure out what kind of document it's dealing with. Only if this header is missing will the browser try to find an HTML meta tag which gives it the same information as a fallback.
It makes sense to set both flags though, since you may save the HTML document to disk, in which case the HTTP header will be gone for anyone needing it later.
You can find the exact rules for how a browser determines the document's charset here: http://www.w3.org/TR/html5/syntax.html#determining-the-character-encoding
这篇关于差异元和PHP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!