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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Erik Neves

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

    I need help with utf-8 before i go bald and the rest of my hair turns
    white!

    Platform:
    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"
    "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dt d">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Unicod e Test</title>
    </head>
    <body><p>
    <?php
    $macRom = 'métallique arquée'; // typed in a bbedit for mac
    echo iconv('MacRoman ', 'UTF-8', $macRom);
    ?>
    </p></body></html>

    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
    missing?

    Thank you all.
  • Nick Kew

    #2
    Re: Unicode generated by php [iconv()] doesn't show properly

    In article <4ce7d0c9.03082 71637.1b08d67c@ posting.google. com>, one of infinite monkeys
    at the keyboard of erik@tba.com.br (Erik Neves) wrote:[color=blue]
    > behaving differently from the very same output of that page? What am I
    > missing?[/color]

    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 http://www.webthing.com/~nick/cv.html

    Comment

    • Alan J. Flavell

      #3
      Re: Unicode generated by php [iconv()] doesn't show properly

      On Thu, Aug 28, Erik Neves inscribed on the eternal scroll:
      [color=blue]
      > Please disregard this post.[/color]

      I could resist that invitation ;-)
      [color=blue]
      > I alredy found the answer.[/color]

      You already found _an_ answer, it seems. And a good one, in practical
      terms, but it still leaves some details unclear.
      [color=blue]
      > FWIMC, I just added a
      >
      > header('Content-Type: text/html; charset=utf-8');
      >
      > before any content and everything worked just fine.[/color]

      It should do...
      [color=blue]
      > It seems that the
      > tag
      > <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      > is not enough.[/color]

      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"
      parameter).
      [color=blue]
      > Now I can have a site with a Russian interface and Japanese contents,
      > just for the fun of it! Thanks to Unicode.[/color]

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

      cheers

      (f'ups narrowed - this isn't a specifically PHP issue.)

      Comment

      • joncarlo1
        New Member
        • Jun 2006
        • 1

        #4
        Apache 2.0 config is the issue

        You need to change the apache server config from:
        AddDefaultChars et UTF-8

        to

        AddDefaultChars et ISO-8859-1

        Then restart Apache webserver

        /etc/httpd/conf/httpd.conf

        That should take care of it.

        JC

        Comment

        Working...