views:

18

answers:

3

I am working on a website and when I try to validate the page get the following error:

The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the element (utf-8). I will use the value from the HTTP header (iso-8859-1) for this validation.

Here is the code in my header:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>

I don't see where the iso-8859-1 is coming from. Any suggestions?

Thanks.

+1  A: 

Check the default HTTP headers that are sent (you can see this in firebug in the NET tab, if you use it).

There is probably a Content-Type header set to iso-8859-1.

HTTP headers are is different from the HTML header (which is part of the body of the HTTP message) - where your META tag specifies UTF-8 as the content type.

Since the two values are incompatible, you are getting an error.

Solution:

  • Make both content-types identical (either UTF-8, or iso-8859-1)
Oded
+1  A: 

It's the webserver which specify the encoding in the HTTP header. It set it to iso-8859-1. But in your page, you wrote:

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

these two values are incompatible. I can only suppose that the webserver is right (it has sent the data anyway), and the validator makes the same assumption.

If you want to send UTF-8 encoded files, check that the content is really UTF8 encoded, and check the header informations. Ultimately the behavior depends on the webserver configuration and page generation.

Maupertuis
+1  A: 

That's the header of your HTML file, not the HTTP headers the server is sending. The meta element defines equivalents to HTTP headers. If both an HTTP header is sent and a meta element exists with the equivalent, the user agent must decide which to use. It might work in your browser but it seems the validator your are using gives precedence to the actual HTTP header.

So you have to figure out how to make your server send the correct Content-type header. If your page is generated by a PHP script you can use header('Content-type:text/html;charset=UTF-8'); at the beginning of your script to fix it.

bobdiaes