如何修复HTML文档的字符编码未声明问题

3

我的网站在本地主机localhost上运行没有任何错误;但是当我将我的网站添加到CPpanel中并运行members.php页面时,页面消失了(只显示白色背景)。

在控制台中检查该页面会显示这个错误信息:

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 be declared in the document or in the transfer protocol.

检查元素只显示以下行:
<div style="clear:both;"></div>


    </div>
</div>
</body>
</html>

这个问题可能已经在这里得到了解答? https://dev59.com/uGct5IYBdhLWcg3wkuLE - Lauri Elias
2个回答

3

从您收到的错误中, 请将以下内容添加到您的<head> ... </head>中:

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-5"> 

如果上面的字符集无法正常工作,请尝试使用以下内容:
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">

我希望您将页面的前BODY部分定义为以下内容:

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>

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

<title> Your Title</title>
</HEAD>
<BODY>
....

编辑2:
members.php中引用其他任何PHP文件之前,请首先输入此行:

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

同样的白色页面,没有改变任何东西。 - Tje
是的,其他页面都没问题。只有在members.php页面出现了这个问题。谢谢。 - Tje
好的。members.php 页面中是否包含其他文件? - user3522371
@Bengueradj 是的,dbconfig.php已经被包含在内,同时还有一些链接指向其他页面。 - Tje
@Tje 请尝试我的答案中的编辑2中的解决方案,并告诉我它是否有效。 - user3522371
显示剩余2条评论

1

您的头部文件中是否有类似这样的内容?您可以将其替换为文件的utf-8编码。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接