By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

Unicode generated by php [iconv()] doesn't show properly

P: n/a
I need help with utf-8 before i go bald and the rest of my hair turns

Mac OS X 10.2.6
Safari 1.0 (v85)
Internet Explorer:mac 5.2.3 (5815.1)
Apache 2.0.47
PHP 4.3.2 (Apache 2 module)
libiconv 1.8

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Unicode Test</title>
$macRom = 'métallique arquée'; // typed in a bbedit for mac
echo iconv('MacRoman', 'UTF-8', $macRom);

When I run this script, I get, both in Safari and Explorer,
métallique arquée
and not
métallique arquée

But, that's why I'm going crazy, *if* I save this output as an html
file and load it in Safari, *it shows the proper accents*!

Now, can somebody please explain me why a page generated using PHP is
behaving differently from the very same output of that page? What am I

Thank you all.
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
In article <4c************************** >, one of infinite monkeys
at the keyboard of er** (Erik Neves) wrote:
behaving differently from the very same output of that page? What am I

At a guess, maybe your server is setting a different charset.
Last time I looked, Apache defaults to iso-8859-1 unless you
tell it to do otherwise.

Nick Kew

In urgent need of paying work - see
Jul 16 '05 #2

P: n/a
On Thu, Aug 28, Erik Neves inscribed on the eternal scroll:
Please disregard this post.
I could resist that invitation ;-)
I alredy found the answer.
You already found _an_ answer, it seems. And a good one, in practical
terms, but it still leaves some details unclear.
FWIMC, I just added a

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

before any content and everything worked just fine.
It should do...
It seems that the
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
is not enough.
Which is exactly what Appendix C to XHTML/1.0 says: it is not enough.

Even with HTML, there is an issue: if the server is configured to send
a different charset than what you put into META, then what the server
sent is specified to take priority. So you need to keep control of
your server anyway, and the W3C recommend (rightly so, in my opinion)
to use the server's real HTTP header on the transaction, in preference
to using (or trying to use) meta stashed inside the document.

But in XHTML (which is what you're evidently aiming at), "meta" comes
too late, and means nothing (to XHTML). You'd only put it there (if
you use it at all) in XHTML/1.0, for the reason of compatibility with
older browsers (and other user agents), but for XHTML you'd need to
conform with XML's rules also, as set out in Appendix C. And here
again, life is simplest if you use the real HTTP content-type header
to specify your character encoding (that so-called "charset"
Now I can have a site with a Russian interface and Japanese contents,
just for the fun of it! Thanks to Unicode.

And some right-to-left scripts for a dessert. ;-)


(f'ups narrowed - this isn't a specifically PHP issue.)
Jul 16 '05 #3

P: 1
You need to change the apache server config from:
AddDefaultCharset UTF-8


AddDefaultCharset ISO-8859-1

Then restart Apache webserver


That should take care of it.

Jun 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.