471,602 Members | 1,293 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,602 software developers and data experts.

HELP utf8 safari VS firefox

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("");

?>

Aug 21 '06 #1
4 2689
*** 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).
--
-+ http://alvaro.es - lvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programacin web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 21 '06 #2
I still get "é" rather than "" in my alert in safari... :(

even with

// action.php

<?php

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

echo "";

?>
Aug 21 '06 #3
twigster wrote:
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">

--
Bart

Aug 22 '06 #4
Bart Van der Donck wrote:
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

--
Bart

Aug 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Christine Forber | last post: by
5 posts views Thread by Bill Cohagan | last post: by
34 posts views Thread by Simon Wigzell | last post: by
3 posts views Thread by Jeff Paffett | last post: by
15 posts views Thread by GinnTech | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.