PDA

View Full Version : encoding HTTP header


gentleone
11-05-2009, 01:48 PM
I have a doctype set to XHTML 1.0 Strict.
I want to use the UTF-8 charset.
If I validate the page it says the following:
The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the <meta> element - utf-8. I will use the value from the HTTP header (iso-8859-1) for this validation.

So how do I change the encoding in the HTTP header? I did check at Modify --> Page Properties --> Title/Encoding and it says there that the encoding is Unicode 5.0 UTF-8.

So what to do? I don't want to use iso-8859-1, because then I have to code for example a normal "&" as "&amp;" which I can do of course, but first this gives me more and unnecessary work and second if I parse for example a RSS feed and they used the normal "&" then I have an error.

I hope that someone can give me advice on this because it start to drive me crazy :roll:

Thanks in advance!

domedia
11-05-2009, 04:23 PM
The characterset should be dfined in the XML declaration, the first lines of your document.

gentleone
11-05-2009, 05:55 PM
Thanks for your reply!
Sorry... I forgot to mention in my previous post.
I did try already <?xml version="1.0" encoding="utf-8" ?> in the first line without the <meta> element version, but then the whole page won't load at all. It gives a white page with a server alert that there is an error on the first line.

domedia
11-05-2009, 06:50 PM
Then it sounds like something else is wrong with your page.
There should be no problems declaring the document as XML.
http://www.w3.org/International/tutorials/tutorial-char-enc/

gentleone
11-06-2009, 06:03 AM
I really don't know what I'm doing wrong, Domedia.

Can you please take a look at the source of the following documents? Perhaps you can see what I'm doing wrong. If you validate indexter2.php then it says that he can't see a doctype at all.

Original:
http://www.gentlemedia.nl/indexter.php

XML decleration:
http://www.gentlemedia.nl/indexter2.php

Thanks in advance!

edbr
11-06-2009, 07:10 AM
http://www.gentlemedia.nl/indexter2.php (http://www.gentlemedia.nl/indexter2.php)
it looks like a php error

gentleone
11-06-2009, 07:45 AM
Okay! I did a test and removed the php includes (RSS feeds) and saved the page as a html document. The page loads fine like this, but I still get the encoding mismatch warning. I really can't change the encoding in the HTTP header from iso-8859-1 to UTF-8 even with the XML declaration in the first line.

This is what I have above the <head>:
<?xml version="1.0" encoding="utf-8" ?>
<!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" lang="en" xml:lang="en">

Page:
http://www.gentlemedia.nl/indexter2.htm

Validation output:
http://validator.w3.org/check? (http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gentlemedia.nl%2Findext er2.htm&charset=%28detect+automatically%29&doctype=Inline&group=0&st=1&accept=application%2Fxml%2Capplication%2Fxhtml%2Bx ml%2Ctext%2Fhtml%3Bq%3D0.9%2Ctext%2Fplain%3Bq%3D0. 8%2Cimage%2Fpng%2C*%2F*%3Bq%3D0.5&accept-language=en-us&user-agent=W3C_Validator%2F1.654)

gentleone
11-06-2009, 08:54 AM
Well, I finally found the solution how I change the HTTP header in my PHP document. Instead of using in the first line:
<?xml version="1.0" encoding="UTF-8" ?>
I had to code it this way:
<?php header('Content-Type:text/html; charset=UTF-8'); ?>

But!!! I thought with UTF-8 a normal "&" would validate, but unfortunately it doesn't. It still says that I have to use "&amp;" instead.

Hmmmm... confused!

gentleone
11-06-2009, 10:37 AM
I'm a happy coder again :)

Problem solved! It had noting to do with the encoding in the HTTP header, but was indeed a PHP issue. I had to add .htmlentities() to some variables in the RSS to HTML script.

I wanna thank those who took the time to help me.