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

查看:13
本文介绍了如何将 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:

字符编码不匹配!

中指定的字符编码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 configuration. The .htaccess file looks like this at the moment:

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

但我已经尝试了 此页面上显示的所有修复程序 他们都没有工作.我怎样才能摆脱这个警告?

But I have tried all the fixes shown on this page and none of them worked. How can I go about getting rid of this warning?

在 Firefox 中,如果您右键单击页面并选择查看页面信息",default.html 显示为 ISO-8859-1,而所有其他页面显示为 UTF-8.

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.

所有的 html 文件都以完全相同的方式创建和保存(字符编码设置为 UTF-8,没有 BOM),但 default.html 是唯一一个不显示为 UTF-8 的文件.所以我假设服务器正在对 default.html 文件做一些特殊的事情,尽管我不确定是什么,因为 .htaccess 文件中没有它的迹象.

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');
?>

请注意,上述内容必须是您文件中的第一件事.没有例外.请参阅header.

Note that the above must be the first thing in your file. No exceptions. See header.

有关如何在不同网络堆栈中更改字符集标头的一般信息,请参阅设置 HTTP 字符集参数.

For general information on how to change the character set header in different web stacks, see Setting the HTTP charset parameter.

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

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