使用HTML符号实体而不是实际的符号 [英] Using HTML Symbol Entities instead of the actual symbol

查看:94
本文介绍了使用HTML符号实体而不是实际的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何特殊的原因,我应该使用HTML符号实体而不是实际的符号(我的意思是我可以输入的符号)?例如符号 / ;它的HTML实体代码是&#47



我应该使用符号的代码还是符号本身在我的HTML代码中,为什么?

解决方案

使用HTML实体引用可以使实体无论编码如何应用于文档。这是好处。



与所有非US-ASCII字符严格使用实体相比,您可以随意使用支持文档目标语言的文档编码,最好还支持其他语言,如UTF-8。然而,请避免使用任何特定于系统的编码,尤其是常规的Windows编码。通常情况下,Windows-1252文本被发送到ISO-8859-1标签错误的其他系统。



过去肯定有更少的可靠地支持数字HTML实体而不是命名HTML实体(基于我自己的第一人称目击者观察),但理论上数字HTML实体仍然是字符编码独立和安全的,因为数字值直接指代码点在UCS中注册( http://en.wikipedia.org/wiki/Universal_Character_Set )和同等学历到其定义的字符名称。



注意:以下描述了我自己的体验,并且您的体验可能会有所不同。




  • 客户端传送给我的HTML文档使用直接嵌入的符号进行处理通常会损坏,无法恢复。这可能是美国基础设施的薄弱环节,也可能是我的客户对如何发送文件缺乏了解。一个主要语言依赖非ASCII字符的国家的基础设施和人员将更有可能支持和了解如何正确传输他们的文档而不会造成损坏。

  • 如果您正在开发自己的网站并将自己的文件的最终副本上传到您的服务器,那么腐败的风险非常小。 如果从编辑它的角度来看,如果您不能控制文档,那么就要承担风险(可能不是今天,但肯定在最近几年在美国,可能不仅仅是风险),因为无论您尝试查看哪种编码,文档都会在某个时间点被不正确地转换,并永久损坏。


Is there any particular reason I should use HTML symbol entities instead of the actual symbol (I mean the one which I can just type)? For example the symbol /; the HTML entity code for it is &#47.

Should I use the symbol's code or the symbol itself in my HTML code, and why?

解决方案

Using an HTML entity reference allows the entity to be represented as intended regardless of the encoding applied to the document. That is the benefit.

Rather than strictly using entities for all non-US-ASCII characters, feel free to use an encoding for your document that supports the document's target language, preferably one also supporting other languages, like UTF-8.

However, please avoid using any system-specific encoding, especially regular Windows encoding. It is often the case that Windows-1252 text is sent to other systems with the wrong label of ISO-8859-1.

In the past there has certainly been been less reliable support for numeric HTML entities than for named HTML entities (based on my own first-person eye witness observation), but in theory a numeric HTML entity is still character encoding independent and "safe" because the numeric value refers directly to a code point registered in the UCS (http://en.wikipedia.org/wiki/Universal_Character_Set) and equivalent to its defined character name.

Caveat: the following describes my own experience, and yours may vary.

  • HTML documents transferred by clients for me to work on with symbols directly embedded are very often corrupted and cannot be recovered. This may be a weakness of U.S. infrastructure or a lack of knowledge on the part of my customers about how to send their documents. The infrastructure and people in a country whose primary language relies on non-ASCII characters would be much more likely to support and understand how to properly transfer their documents with no corruption.

  • If you are developing your own website and uploading the final copies of your own files to your server, then the risk of corruption is very small.

  • If you do not have control over your document from the point you edit it to the point that it is served to users, then you run the risk (perhaps not today, but certainly within recent years in the U.S., a likelihood more than mere risk) of having the document improperly converted at some point along the way and being permanently corrupted regardless of what encoding you attempt to view it in.

这篇关于使用HTML符号实体而不是实际的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆