gpt4 book ai didi

html - 什么时候应该使用 HTML 实体?

转载 作者:技术小花猫 更新时间:2023-10-29 11:27:38 24 4
gpt4 key购买 nike

这让我困惑了一段时间。随着 UTF-8 作为 Web 开发中的事实标准的出现,我不确定在哪些情况下我应该使用 HTML 实体以及在哪些情况下我应该只使用 UTF-8 字符。例如,

  • 破折号 (–, &emdash;)
  • 和号 (&, &)
  • 3/4 分数 (¾, ¾)

请阐明这个问题。我们将不胜感激。

最佳答案

根据我收到的评论,我进一步调查了这个问题。目前看来,最佳做法是放弃使用 HTML 实体,而改用实际的 UTF-8 字符。列出的原因如下:

  1. UTF-8 编码对于理解字符含义并知道如何输入的人来说更容易阅读和编辑。
  2. UTF-8 编码对于那些不理解它们的人来说就像 HTML 实体编码一样难以理解,但它们具有呈现为特殊字符的优势,而不是难以理解的十进制或十六进制编码。

只要您的页面编码正确设置为 UTF-8,您就应该使用实际字符而不是 HTML 实体。我阅读了一些关于这个主题的文档,但最有帮助的是:

来自UTF-8:字符编码的 secret 一文:

Wikipedia is a great case study for an application that originally used ISO-8859-1 but switched to UTF-8 when it became far too cumbersome to support foreign languages. Bots will now actually go through articles and convert character entities to their corresponding real characters for the sake of user-friendliness and searchability.

那篇文章还给出了一个涉及中文编码的很好的例子。为了懒惰,这里是一个简短的例子:

UTF-8:

这两个字是什么意思

HTML 实体:

這兩個字是甚麼意思

UTF-8 和 HTML 实体编码对我来说都没有意义,但至少 UTF-8 编码可以识别为外语,并且它会在编辑框中正确呈现。文章接着说了以下关于 HTML 实体编码版本的内容:

Extremely inconvenient for those of us who actually know what character entities are, totally unintelligible to poor users who don't! Even the slightly more user-friendly, "intelligible" character entities like θ will leave users who are uninterested in learning HTML scratching their heads. On the other hand, if they see θ in an edit box, they'll know that it's a special character, and treat it accordingly, even if they don't know how to write that character themselves.

正如其他人所指出的,您仍然必须对保留的 XML 字符(与号、小于号、大于号)使用 HTML 实体。

关于html - 什么时候应该使用 HTML 实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/436615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com