< meta charset =" utf-8">声明自己的文件的编码? [英] <meta charset="utf-8"> declares encoding of own file?
问题描述
我读到一个HTML文件必须包含头中的
< meta charset =utf-8>
code> - 要符合标准。
I read that an HTML file has to contain the <meta charset="utf-8">
element in the head
-element to be standard-conforming.
为什么指定文件本身的编码是有意义的?为了读取 meta
-element,必须知道编码;
Why does it make sense to specifiy the encoding of a file in the file itself? In order to read the meta
-element one has to know the encoding already; so it seems redundant/useless to specify the encoding again.
推荐答案
直到读取这个元素,文档才会被解释为默认的编码用户代理。如果编码与默认值不同,则根据元元素重新解释文档。这就是为什么你应该尽早放置它,或者最好使用HTTP头(见下文)。使用< meta>
元素的希望是前面的字符都在ASCII字符集中,在所有字符集中正确解释。
Until this element is read, the document is interpreted with the default encoding of the user agent. If the encoding is different from the default, then the document is re-interpreted according to the meta element. That's why you should place it as early as possible, or preferably use an HTTP header (see below). The hope with the <meta>
element is that the preceding characters are all in the ASCII character set, which are interpreted correctly in just about all character sets.
但是,一般情况下,如果可能,此信息应该在HTTP响应头中发送:
In general, however, and if it is possible, this information should be sent in an HTTP response header:
Content-Type: text/html; charset=utf-8
这可以确保文档从头开始正确解释。
This ensures that the document is interpreted correctly from the start.
这篇关于< meta charset =" utf-8">声明自己的文件的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!