Unicode字符或编码实体 [英] Unicode characters or encoded entities

查看:84
本文介绍了Unicode字符或编码实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML页面中使用了一些特殊字符,例如×(×)或…(…).

I'm using some special characters like × (×) or … (…) in my html pages.

在某些地方,我直接使用unicode字符,但在某些地方,我使用的是诸如&hellip之类的编码实体.

Somewhere I'm using unicode character directly, but somewhere I'm using encoded entity like &hellip.

我想整理我的代码,无法确定哪种表示法更好.

I want to tidy up my code and can't decide what notation is better.

我只能发现两个优点和缺点:

I could find just two pros and cons:

  • 直接使用字符,我可以使用text方法(如$("#button").text("Loading…"))而不是html来设置javascript中的文本,这可能会导致XSS问题
  • 直接使用字符可能会导致编码问题,如果服务器配置错误
  • using character directly I can set text in javascript using text method like $("#button").text("Loading…"), instead of html which could lead to XSS issues
  • using characters directly can lead to encoding issues in case of misconfigured server

也许我错过了一些重要的事情?最佳做法是什么?

Maybe I'm missing something important? What is the best practice?

推荐答案

如果直接使用Unicode,则有人可能会使用错误的编码来保存文件,并且所有字符都将被弄乱.

If you use Unicode directly there's a chance that someone saves the file with the incorrect encoding and all characters get mangled.

另一方面,使用实体代码意味着您无法在源代码中进行有效搜索;您必须记住每个非ASCII字符的编码方式.数据库内容也是如此.可读性也受到损害.

On the other hand, using entity codes means you can't search effectively in the source code; you have to remember how each non ASCII character is encoded. Same goes for database content. Readability suffers,too.

我更喜欢直接使用Unicode,并且团队中的每个人都知道文件必须以UTF-8编码.

I prefer to use Unicode directly and everyone on the team knows that files must be encoded in UTF-8.

这篇关于Unicode字符或编码实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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