UTF-8编码的html页面显示 (问号)而不是字符 [英] UTF-8 encoded html pages show � (questions marks) instead of characters

查看:867
本文介绍了UTF-8编码的html页面显示 (问号)而不是字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在win7(x64)上安装了标准XAMPP。
在过去的项目中,我的共享编码麻烦,其中mysql编码不匹配的php enconding,反过来有时输出html在其他编码,我决定使用utf-8一致编码的一切。

I have the standard XAMPP installation on win7 (x64). Having had my share of encoding troubles in a past project where mysql encoding did not match with the php enconding which in turn sometimes output html in other encodings, I decided to consistently encode everything using utf-8.

我刚刚开始使用html标记,并且遇到了麻烦。

I'm just getting started with the html markup and am allready experiencing troubles.


  • 页面是使用utf-8保存的(没有BOM,我认为)

    //更新:原来不是这样。该文件实际保存与 ISO_8859-1 。我后来发现这一点谢谢谢姆彭德利斯答案。我必须返回并将我的项目设置(设置为ISO-8859-1)更改为所需的UTF-8。

  • php已设置每个.htaccess在utf-8中提供.php页面: AddCharset UTF-8 .php

  • html有一个元标记指定:< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>

  • 要测试我设置使用的php header('Content-Type:text / html; charset = UTF-8');

  • My page is saved using utf-8 (no BOM, I think)
    //update: It turns out this was NOT the case. The file was actually saved with ISO_8859-1. I later found this out thanks to Sherm Pendleys answer. I had to go back and change my project settings (which were set to "ISO-8859-1") to the desired "UTF-8".
  • php is set per .htaccess to serve .php-pages in utf-8 with: AddCharset UTF-8 .php
  • html has a meta tag specifying: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  • To test I set used php header('Content-Type:text/html; charset=UTF-8');

这个页面显然是以utf-8提供的(firefox和chrome会如此识别),但任何特殊字元,例如éá¡将只显示为

The page is evidently served in utf-8 (firefox and chrome recognize it as such) but any special characters such as é, á or ¡ will just show as . Also when viewing the source code.

当删除上面提到的编码设置时,所有字符都会正确呈现,但检测到的编码显示 windows- 1252 ISO-8859-1 (取决于浏览器)。

When dropping the encoding settings mentioned above all characters are rendered correctly but the encoding that is detected shows either windows-1252 or ISO-8859-1 depending on the browser.

我很困惑。我希望完全相反的行为。

欢迎任何建议,谢谢!

How come? I'm very puzzled. I would have expected the exact opposite behavior.
Any advice is welcome, thanks!

编辑:
希望这有助于更多。这是响应头(根据firebug)

edit: Hopefully this helps a bit more. This is the response header (as per firebug)

HTTP/1.1 200 OK
Date: Sat, 26 Mar 2011 20:49:44 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Content-Length: 91
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8


推荐答案


当[丢弃]编码设置
上面提到的所有字符
[被渲染]正确,但
检测到的编码显示
windows-1252或ISO-8859-1
,取决于浏览器。

When [dropping] the encoding settings mentioned above all characters [are rendered] correctly but the encoding that is detected shows either windows-1252 or ISO-8859-1 depending on the browser.

这就是你真正发送的。您的项目符号列表中的编码设置都不会以任何方式实际修改您的输出;他们所做的就是告诉浏览器在解释你发送什么时采用什么编码。这就是为什么你得到那些 - 你告诉浏览器,你发送的是UTF-8,但它是真正的ISO-8859-1。

Then that's what you're really sending. None of the encoding settings in your bullet list will actually modify your output in any way; all they do is tell the browser what encoding to assume when interpreting what you send. That's why you're getting those �s - you're telling the browser that what you're sending is UTF-8, but it's really ISO-8859-1.

这篇关于UTF-8编码的html页面显示 (问号)而不是字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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