HELP utf8 safari VS firefox

T

twigster

Hi,

I've a pb with utf8 encoding with safari or firefox.

I retrieve the response of a XMLHttpRequest and depending if I use
safari or firefox I can't manage to get characters like "éàç"

to see an illustration you can try the code below :
(with this code I get a "é" with firefox but not with safari. I need to
add a ut8_decode to get the "é"!)
RQ : the files are encoded in utf8

thank you

// index.php :

<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>untitled</title>

</head>

<body>

<script type="text/javascript" charset="utf-8">

function search() {
var xmlHttp;
if (window.ActiveXObject) xmlHttp = new
ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
else { alert('JavaScript error : problem with
XMLHttpRequest objects ...'); return;}
var url = "action.php";
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
if (xmlHttp.readyState == 4) { print(xmlHttp.responseText) }
}

function print (response) {
alert(response);
}

search();

</script>


</body>
</html>

-----------------------------------------------------
// action.php

<?php

echo "é";
// or
//echo ut8_decode("é");

?>
 
A

Alvaro G. Vicario

*** twigster escribió/wrote (Mon, 21 Aug 2006 23:42:33 +0200):
// action.php

<?php

echo "é";
// or
//echo ut8_decode("é");

?>

I don't know if browsers obey HTTP headers under this situation, but it's
always good practice to make sure you have a correct Content-Type header.
If web server doesn't generate the correct one, do it yourself:

<?php

header('Content-Type: text/html; charset=UTF-8');

echo "é";

?>

.... given than you save the file as UTF-8 (all good editors allow you to
choose).
 
T

twigster

I still get "é" rather than "é" in my alert in safari... :(

even with

// action.php

<?php

header('Content-Type: text/html; charset=UTF-8');

echo "é";

?>
 
B

Bart Van der Donck

twigster said:
I still get "é" rather than "é" in my alert in safari... :(
even with

// action.php
<?php
header('Content-Type: text/html; charset=UTF-8');
echo "é";
?>

I'ld say that the output stream should be correct when it shows 'é';
I think it's rather the browser that doesn't know how to represent the
offered data. A route from 'é' to 'é' uses a UTF-8 code table for
sure; since it corresponds to hex C3 ('Ã') plus hex A9 ('©'),
together forming Unicode's "LATIN SMALL LETTER E WITH ACUTE" ('é' or
hex E9 in "traditional" sets).

More info, search for 'C3A9' on:
http://home.tiscali.nl/t876506/utf8tbl.html

For the basic values, see table on
http://en.wikipedia.org/wiki/ISO_8859-1

Did you save action.php in UTF-8 mode ?

I'ld suggest to add meta-information in your page header as well:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
B

Bart Van der Donck

Bart said:
I'ld say that the output stream should be correct when it shows 'é';
I think it's rather the browser that doesn't know how to represent the
offered data. A route from '駠to 'é' uses a UTF-8 code table for
sure; since it corresponds to hex C3 ('ç) plus hex A9 ('?'),
together forming Unicode's "LATIN SMALL LETTER E WITH ACUTE" ('駠or
hex E9 in "traditional" sets). [...]

It appears that at least Google Groups doesn't show these chars as they
were intended (which indicates again how messy character encoding in
browsers can be).

My post in GIF format:
http://www.dotinternet.be/temp/code.gif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top