gpt4 book ai didi

php - 未在 html 文档中声明的字符编码

转载 作者:IT王子 更新时间:2023-10-29 00:16:17 25 4
gpt4 key购买 nike

我有一个文件出现了一个非常奇怪的错误。错误是:

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();
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>

这是一个不抛出错误的文件 (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('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>

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

最佳答案

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

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

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

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

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

关于php - 未在 html 文档中声明的字符编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11633162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com