简体   繁体   English

使用UTF-8时是否应该编码HTML特殊字符?

[英]Should I encode HTML special characters when using UTF-8?

I heard recently that it is no longer required to encode HTML special characters when using the UTF-8 (or Unicode) charset on a web site. 我最近听说,在网站上使用UTF-8(或Unicode)字符集时,不再需要对HTML特殊字符进行编码。

I mean non-ASCII characters, such as « («), — (—), and similar. 我的意思是非ASCII字符,例如«(«),-(—)等。 Characters reserved in HTML should be escaped of course (>, “, and so on). HTML中保留的字符当然应该转义(>,“等等”)。

If is it true, preparing large texts for publishing on the web would be much easier than before. 如果确实如此,那么准备大文本以在网络上发布将比以前容易得多。

It has never been required to “encode” characters (escape them with character references like &#8212; or entity references like &mdash; ) when using UTF-8, during the time that browsers have supported UTF-8 in the first place. 在使用UTF-8的过程中,从来没有要求对字符进行“编码”(使用&#8212;等字符引用或&mdash;等实体引用进行转义),而这恰恰是在浏览器首先支持UTF-8的时候。 The only exceptions are the less-than character “<” and the ampersand “&”, which need to be escaped independently of encoding. 唯一的例外是小于字符“ <”和与号“&”,它们需要独立于编码进行转义。 (Well, a quotation mark cannot be used as such inside a quoted attribute value that has the same mark as delimiter, but this can usually be avoided.) (好吧,不能在带有引号的属性值中使用引号,而引号属性值与定界符具有相同的标记,但是通常可以避免这种情况。)

You may still use escape notations. 您仍然可以使用转义符号。 You might do so if you expect that you, or someone else, will have to edit the HTML document so that the authoring tools do not have appropriate UTF-8 support. 如果您希望自己或其他人必须编辑HTML文档,以使创作工具没有适当的UTF-8支持,则可以这样做。 You might also do that because you are typing in text and have no handy tool for inserting all characters as such. 您可能还会这样做,因为您正在输入文本,并且没有方便的工具可以像这样插入所有字符。 But these are exceptions. 但是这些都是例外。

It's true. 这是真的。

Using HTML Entities (except for special chars) has been quite out of fashion since UTF-8 took over. 自从UTF-8接管以来,使用HTML实体(特殊字符除外)已经过时了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM