Html 带重音的 E 显示不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12952784/
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 03:26:45  来源:igfitidea点击:

E with accent doesn't show correctly

htmlcharacter-encoding

提问by drake035

On my page, the text in the top middle (? Ce site Internet. ?) contains E with accents which on my computer appear as question marks.

在我的页面上,顶部中间的文本(?Ce 站点 Internet。?)包含带有重音符号的 E,在我的计算机上显示为问号。

This is despite the fact that I have meta charset="UTF-8" in my head tag and the PHP file containing the text appears as UTF-8 when opened with Notepad++.

尽管事实上我的 head 标签中有 meta charset="UTF-8" 并且包含文本的 PHP 文件在使用 Notepad++ 打开时显示为 UTF-8。

What's going on then?

那是怎么回事?

回答by twodayslate

The browser displays these when it can't make sense of the numbers it is reading. UTF-8 is self-synchronzising. Unlike other multi-byte character encodings, you always know where you are with UTF-8. If you see a number 192-247, you know you are at the beginning of a multi-byte sequence. If you see 128-191 you know you are in the middle of one. There's no danger of missing the first number and garbling the rest of the text. This means that in UTF-8, the sequence 191 followed by 224 will never occur naturally, so the browser doesn't know what to do with it and displays ?? instead.

当浏览器无法理解正在读取的数字时,它会显示这些。UTF-8 是自同步的。与其他多字节字符编码不同,您始终知道使用 UTF-8 的位置。如果您看到一个数字 192-247,您就知道您处于多字节序列的开头。如果您看到 128-191,您就知道您处于其中之一。没有遗漏第一个数字和乱码其余文本的危险。这意味着在 UTF-8 中,191 后跟 224 的序列永远不会自然出现,所以浏览器不知道如何处理它并显示 ?? 反而。

Use the following in your head tag:

在 head 标签中使用以下内容:

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

See: http://coding.smashingmagazine.com/2012/06/06/all-about-unicode-utf8-character-sets/

参见:http: //coding.smashingmagazine.com/2012/06/06/all-about-unicode-utf8-character-sets/

回答by deceze

The page is not actually encoded in UTF-8, it is encoded in Latin1. You need to actuallysave the source code files in UTF-8 or otherwise make sure they are output encoded in UTF-8. Currently you have a rift between what the site claims to be encoded in and what it is actually encoded in.

该页面实际上不是用 UTF-8 编码的,而是用 Latin1 编码的。您需要实际以 UTF-8 格式保存源代码文件,或者确保它们以 UTF-8 编码输出。目前,网站声称编码的内容与实际编码的内容之间存在分歧。

回答by Stuart Wakefield

Although you are announcing the content as UTF-8 in the meta and the HTTP headers, it is not UTF-8 that is being sent. You might need to check your PHP settings that it is actually outputting content in the correct encoding. http://php.net/manual/en/mbstring.configuration.php.

尽管您在元数据和 HTTP 标头中宣布内容为 UTF-8,但发送的并不是 UTF-8。您可能需要检查您的 PHP 设置,以确保它实际上以正确的编码输出内容。http://php.net/manual/en/mbstring.configuration.php

回答by Tom Oakley

Did you use the ASCII/HTML codes for the accented characters? If not, here's a list of them. Search for 'E acute' and you should fine the code for that character (it's &Eacute;I think). At first I thought it was the font-family you were using but I don't think it is because I disabled all styles in my browser and they still appeared as question marks.

您是否对重音字符使用了 ASCII/HTML 代码?如果没有,这里是它们的列表。搜索“Eacute”,您应该对那个字符的代码进行修改(&Eacute;我认为是这样)。起初我以为这是您使用的字体系列,但我不认为这是因为我禁用了浏览器中的所有样式,它们仍然显示为问号。

More HTML character entities can be found at https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

更多 HTML 字符实体可以在https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references找到