1

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.

Community
  • 1
  • 1
Ormoz
  • 2,975
  • 10
  • 35
  • 50
  • 1
    `` with stron on *T*ype – yergo Jan 14 '16 at 15:42
  • @yergo I already have that in the head – Ormoz Jan 14 '16 at 15:44
  • https://www.w3.org/TR/html5/syntax.html#syntax-doctype specifies that DOCTYPE needs to be the first tag on the page, which I think might be what the problem is. Put your PHP after it and see if that helps. – John Clifford Jan 14 '16 at 15:44
  • @JohnClifford No, I do not think so, the code before `doctype` just sends a header and you could not send headers after any output – Ormoz Jan 14 '16 at 15:46
  • I still think that may be related to the issue you're having with Unicorn's validation. – John Clifford Jan 14 '16 at 15:47
  • @Ormoz, rewrite it case sensitively. Its `Content-Type` not `Content-type` etc. Validators may be sensitive on this. – yergo Jan 14 '16 at 15:55
  • 2
    `` should also be just `` – CD001 Jan 14 '16 at 16:03
  • Possible duplicate of [The character encoding of the HTML document was not declared](http://stackoverflow.com/questions/11996257/the-character-encoding-of-the-html-document-was-not-declared) – yergo Jan 14 '16 at 16:17

1 Answers1

0

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?

yergo
  • 4,761
  • 2
  • 19
  • 41