如何为default.html将字符编码设置为UTF-8? [英] How do I set Character Encoding to UTF-8 for default.html?

查看:332
本文介绍了如何为default.html将字符编码设置为UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了最后几个小时让我的网站验证HTML 4.01 Strict,我实际上已经成功了,但仍有一个警告,我不能摆脱。警告是:

I spent the last few hours getting my website to validate HTML 4.01 Strict and I actually have succeeded in that but there is still one warning which I can't get rid of. The warning is:


字符编码不匹配!

Character Encoding mismatch!


HTTP头(iso-8859-1)是
不同于
元素(utf-8)中的值。我将使用HTTP头中的值
(iso-8859-1)来验证

The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the element (utf-8). I will use the value from the HTTP header (iso-8859-1) for this validation.

相关网页是 www.dubiousarray.net/default.html 。从页面源代码我可以看到以下元素:

The page in question is www.dubiousarray.net/default.html. As you can see from the page source I have the following meta element:

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

我已经确保default.html文件以UTF-8编码保存。奇怪的是网站中的所有其他页面验证没有此警告,他们有相同的元标记,并以完全相同的方式保存。我很确定这是与服务器配置有关。 .htaccess文件现在看起来像这样:

and I have made sure that the default.html file is saved with UTF-8 encoding. The strange thing is all the other pages in the site validate without this warning and they have the same meta tag and were saved in exactly the same way. I am pretty sure it is something to do with the server config. The .htaccess file looks like this at the moment:

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
AddDefaultCharset UTF-8

但我已尝试所有修复此网页,但都无效。有谁有任何想法如何去除掉这个警告?最后,在Firefox中,如果右键单击页面并选择查看页面信息,default.html将显示为ISO-8859-1
,而所有其他页面显示为UTF-8。

but I have tried all the fixes shown on this page and none of them worked. Does anyone have any ideas on how to go about getting rid of this warning? One last thing, in Firefox if you right click on the page and select 'View Page Info', default.html shows as ISO-8859-1 while all the other pages show UTF-8.

感谢,Jacob

编辑:还需要注意的是,所有的html文件都是以完全相同的方式创建和保存的(字符编码设置为UTF-8,没有BOM),但default.html是唯一不显示为UTF-8的字符。所以我假设服务器正在做一些特殊的default.html文件,虽然我不知道什么,因为在.htaccess文件中没有它的标志。

Something else to note is that all the html file have been created and saved in the exact same way (character encoding set to UTF-8 without BOM) but default.html is the only one which isn't displaying as UTF-8. So I assume the server is doing something special to the default.html file though I am not sure what as there is not sign of it in the .htaccess file.

推荐答案

您需要替换HTTP级别的标头。

You need to replace the HTTP-level header.

这应该可以工作:

<?php 
 header('Content-type: text/html; charset=utf-8'); 
?>

请注意,上述必须是文件中的第一件事。没有例外。请参阅
http://us2.php.net/manual/en /function.header.php

Note that the above must be the FIRST thing in your file. No exceptions. See http://us2.php.net/manual/en/function.header.php

有关如何更改不同Web堆栈中的字符集标头的一般信息,请参阅
http://www.w3.org/International/O-HTTP-charset

For general info on how to change the character set header in different web stacks, see http://www.w3.org/International/O-HTTP-charset

Larry

这篇关于如何为default.html将字符编码设置为UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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