HTML Unicode 问题:如何显示特殊字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8922213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:37:31  来源:igfitidea点击:

HTML Unicode Issue: How to display special characters

htmlunicodecharacter-encodingutf

提问by HandiworkNYC.com

Currently, I have my webpage set to Unicode/UTF-8. When trying to display a special character (for example, em dash, double arrow, etc), it shows up as a question mark symbol. I cannot change these characters to the HTML entity equivalent. How can I circumvent this issue?

目前,我的网页设置为 Unicode/UTF-8。当尝试显示特殊字符(例如,长破折号、双箭头等)时,它会显示为问号符号。我无法将这些字符更改为等效的 HTML 实体。我怎样才能规避这个问题?

回答by Jukka K. Korpela

A question mark in a lozenge, ?, indicates a character-level error: the data contains bytes that do no represent any character, according to the character encoding being applied. This typically happens when the document is declared as UTF-8 encoded but is really in iso-8859-1, windows-1252, or some similar encoding. Windows-1252 is a common default encoding used by various programs on Windows platforms. So you may need to open the file in your authoring program and re-save it as UTF-8 encoded.

菱形中的问号 ? 表示字符级错误:根据所应用的字符编码,数据包含不代表任何字符的字节。这通常发生在文档被声明为 UTF-8 编码但实际上是 iso-8859-1、windows-1252 或某些类似编码时。Windows-1252 是 Windows 平台上各种程序使用的常见默认编码。因此,您可能需要在创作程序中打开该文件并将其重新保存为 UTF-8 编码。

If problems remain, please post the URL. Posting the code alone is not sufficient, since the character encoding is primarilyspecified in HTTP headers.

如果问题仍然存在,请发布网址。仅发布代码是不够的,因为字符编码主要在 HTTP 标头中指定。

If you see a question mark in a small box, then it might be a font-level problem (lack of glyph in the fonts being used), but this would be very rare for common characters like the em dash. Different browsers have different ways of indicating character- or font-level problems.

如果您在小方框中看到问号,则可能是字体级别的问题(所使用的字体中缺少字形),但对于像 em 破折号这样的常见字符来说,这种情况非常罕见。不同的浏览器有不同的方式来指示字符级或字体级问题。

回答by HandiworkNYC.com

Make sure your document is set to the correct character encoding in the actual code editor, as well as in the doctype. Both are necessary. I spent hours trying to tweak HTML when the only problem was that I needed to set the text setting in Coda.

确保您的文档在实际代码编辑器以及文档类型中设置为正确的字符编码。两者都是必要的。当唯一的问题是我需要在 Coda 中设置文本时,我花了几个小时试图调整 HTML。

<head>
    <meta charset="utf-8">

See the following screenshot:

请参阅以下屏幕截图:

enter image description here

在此处输入图片说明

回答by Jesse Kinsman

Make sure your characters are actually UTF-8 characters. They will probably look something like this:

确保您的字符实际上是 UTF-8 字符。它们可能看起来像这样:

&#174; or U+0020

http://www.kinsmancreative.com/transfer/char/index.phpis a handy site for finding the decimal values of commonly used UTF-8 special characters if you need a reference.

如果您需要参考,http://www.kinsmancreative.com/transfer/char/index.php 是一个方便的站点,可用于查找常用 UTF-8 特殊字符的十进制值。