简体   繁体   中英

No Character encoding declared at document level

When I validate my website in w3.org , I get the following as info :

No Character encoding declared at document level No character encoding information was found within the document, either in an HTML meta element or an XML declaration. It is often recommended to declare the character encoding in the document itself, especially if there is a chance that the document will be read from or saved to disk, CD, etc. See this tutorial on character encoding for techniques and explanations.

I searched google and tried their suggestions but none worked for me.

I have already applied all suggested solutions in this question with no avail.

Here is the response header of the webpage:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive, close
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Thu, 14 Jan 2016 15:25:27 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache
Transfer-Encoding:chunked
Vary:Accept-Encoding

and the first lines of my HTML file in a php base website:

<?php header('Content-type: text/html; charset=utf-8');?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta content="utf-8" http-equiv="encoding" />
<meta charset="UTF-8" />

I don't know what else I can do to fix that message.

Thank you for your suggestions.

For XML (including XHTML), use the encoding pseudo-attribute in the XML declaration at the start of a document or the text declaration at the start of an entity. Example:

<?xml version="1.0" encoding="utf-8" ?>

From w3 manual . There are some other tricks described.

Also, the html5 specs suggests, that encoding is case sensitive parameter and has to be declared withing first 1024 bytes of the document.

In addition, due to a number of restrictions on meta elements, there can only be one meta-based character encoding declaration per document.

So i would suggest to leave your http header this way:

<?php header('Content-Type: text/html; charset=utf-8');

and leave only one kind of meta declaration, eg.:

<meta charset="utf-8">

Than we will see if it helps.

Also i have uploaded your example and only error I have received has something with bad encoding parameter in http-equiv , what was solved just by deleting this line. Maybe you have some iframes or other documents embedded in your file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM