在 HTML 中显示 unicode 符号 [英] Displaying unicode symbols in HTML

查看:89
本文介绍了在 HTML 中显示 unicode 符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 HTML 页面中简单地显示勾号 (✔) 和十字 (✘) 符号,但它显示为一个框或 goop âœ" - 显然与编码有关.

I want to simply display the tick (✔) and cross (✘) symbols in a HTML page but it shows up as either a box or goop âœ" - obviously something to do with the encoding.

我已将元标记设置为显示 utf-8,但显然我遗漏了一些东西.

I have set the meta tag to show utf-8 but obviously I'm missing something.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

编辑/解决方案:根据使用 FireBug 发表的评论,我发现我的页面传递的标题实际上是Content-Type: text/html"而不是 UTF-8.使用 Notepad++ 查看文件格式显示我的文件格式为UTF-8 without BOM".将其更改为仅 UTF-8,符号现在可以正确显示......但萤火虫似乎仍然表示相同的内容类型.

Edit/Solution: From comments made, using FireBug I found the headers being passed by my page were in fact "Content-Type: text/html" and not UTF-8. Looking at the file format using Notepad++ showed my file was formatted as "UTF-8 without BOM". Changing this to just UTF-8 the symbols now show correctly... but firebug still seems to indicate the same content-type.

推荐答案

您应该确保 HTTP 服务器标头正确.

You should ensure the HTTP server headers are correct.

特别是标题:

Content-Type: text/html; charset=utf-8

应该存在.

如果存在 HTTP 标头,元标记将被浏览器忽略.

The meta tag is ignored by browsers if the HTTP header is present.

还要确保您的文件在提供之前实际编码为 UTF-8,请检查/尝试以下操作:

Also ensure that your file is actually encoded as UTF-8 before serving it, check/try the following:

  • 确保您的编辑器将其保存为 UTF-8.
  • 确保您的 FTP 或任何文件传输程序不会弄乱文件.
  • 尝试使用 HTML 编码的实体,例如 &#uuu;.
  • 可以肯定的是,对文件进行 hexdump 并查看字符,对于 ✔,它应该是 E2 9C 94 .

注意:如果您使用系统找不到字形的 unicode 字符(没有带有该字符的字体),您的浏览器应该显示一个问号或一些块状符号.但是,如果您看到多个罗马字符,则表示存在编码问题.

Note: If you use an unicode character for which your system can't find a glyph (no font with that character), your browser should display a question mark or some block like symbol. But if you see multiple roman characters like you do, this denotes an encoding problem.

这篇关于在 HTML 中显示 unicode 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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