Php html文档中未声明字符编码

Php html文档中未声明字符编码,php,encoding,Php,Encoding,我有一个文件,我得到了一个非常奇怪的错误。错误是: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character en

我有一个文件,我得到了一个非常奇怪的错误。错误是:

The character encoding of the HTML document was not declared. 
The document will render with garbled text in some browser configurations if 
the document contains characters from outside the US-ASCII range. 
The character encoding of the page must to be declared in the document or 
in the transfer protocol.
此文件来自以下文件(indexmws.php):

session_start();
如果(!isset($_会话['validUser'])|$_会话['validUser']!==true){
标题('Location:loginmws.php');
}
包括_once('db.php');
包括_once('amazonmws.php');
包括_once('decidemws.php');
包括_once('author.php');
包括_once('amazonPricingMWS.php');
?>
决策者
除了添加amazonPricingMWS.php并重定向到标题中包含mws.php的页面外,这是一个完全重复的文件,不会引发错误(index.php):

session_start();
if(!isset($_SESSION['validUser']) || $_SESSION['validUser'] !== true){
header('Location: login.php');
}

include_once('db.php');
include_once('amazon.php');
include_once('decide.php');
include_once('author.php');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Decision Maker</title>
session_start();
如果(!isset($_会话['validUser'])|$_会话['validUser']!==true){
标题('Location:login.php');
}
包括_once('db.php');
包括_once('amazon.php');
包括_once('decise.php');
包括_once('author.php');
?>
决策者

有人能解释一下为什么我在indexmws.php中出现这个错误吗?

这个错误是因为浏览器希望文件的前1024个字节采用编码格式。在第一种情况下,可能存在由包括的文件输出的某些内容

浏览器现在缓冲文件的前1024个字节以检查字符编码。如果在前1024字节中未遇到编码描述,则显示此警告

在您的情况下,可以在包含其他文件之前使用php头指定内容类型:

header('Content-type: text/html; charset=utf-8');
有关更多信息,请阅读以下内容:
我也有类似的问题,但这背后的确切原因是我错过了下面要添加的内容

<meta content="utf-8" http-equiv="encoding">

在头标签之后

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


谢谢!这解决了我在firefox中的错误,(我已经解决了,但是HTML需要meta标记。)之后我就使用了你的第一个(虽然我将其结尾改为“/>”,以匹配页面上的标记样式。)@Krishan,你在哪个浏览器上测试过这个?我刚刚尝试了
,它也工作了
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">