字符编码未在html文档中声明 [英] Character encoding not declared in html document

查看:2417
本文介绍了字符编码未在html文档中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 未声明HTML文档的字符编码。 
如果
该文档包含US-ASCII范围以外的字符,则文档将在某些浏览器配置中以乱码文本呈现。
页面的字符编码必须在文档中声明或
在传输协议中。

这个文件来自(indexmws.php):

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

include_once('db.php');
include_once('amazonmws.php');
include_once('decidemws.php');
include_once('author.php');
include_once('amazonPricingMWS.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/xhtmlxml:lang =enlang =en>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> Decision Maker< / title>

这是一个完全重复的文件,不会将错误(index.php)与除了添加amazonPricingMWS.php,并重定向到标题为mws.php的页面:

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

include_once('db.php');
include_once('amazon.php');
include_once('decision.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/xhtmlxml:lang =enlang =en>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> Decision Maker< / title>

任何人都可以向我解释为什么我在indexmws.php中收到此错误?

解决方案

出现错误是因为浏览器期望文件的前1024个字节中的编码格式。在第一种情况下可能是包含文件的一些内容被输出的情况。



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



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

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

有关更多信息,请阅读:
http://gtmetrix.com/specify-a-character-set-early.html


I have a file that I am getting a very weird error on. The error is:

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.

the file this comes from is (indexmws.php):

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

include_once('db.php');
include_once('amazonmws.php');
include_once('decidemws.php');
include_once('author.php');
include_once('amazonPricingMWS.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>

This is an exact duplicate of a file that does not throw the error (index.php)with the exception of adding amazonPricingMWS.php and redirecting to pages with mws.php in the title:

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>

can anyone explain to me why I am getting this error in indexmws.php?

解决方案

The error is coming because the browsers expect the encoding format in the first 1024 bytes of the file. It may be the case that there is some content being outputted by the included files in the first case.

The browsers now buffer the first 1024 bytes of the file to check for the character encoding. If the encoding description is not encountered in the first 1024 bytes, this warning is displayed.

In your case, you can use a php header for specifying the content type before the other files are included:

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

For more information, read this: http://gtmetrix.com/specify-a-character-set-early.html

这篇关于字符编码未在html文档中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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