#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    India
    Posts
    2
    Rep Power
    0

    How do I display UTF-8 chars on a web page?


    You'd think it would be easy, but after hours of Googling, I found LOTS of scholarly information, but none of them actually say how to get the chars to show up on a page. Does anyone know this?

    My goal of my website is to have a variety of languages (and charsets) shown- some on the same page. So, on the same page I want to show the full range of my UTF-8 charset, including latin, roman, chinese, greek, etc. Here's what I've tried:

    1. Header: <?php header("Content-Type: text/html; charset=utf-8"); ?>
    and after the <head> tag I have: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    2. Choose a font that has all UTF-8 chars. One post said some fonts don't have utf-8 chars included, so use the following:

    <style type="text/css"> body {font-family:"Arial Unicode MS";} </style>


    3. I query a MySQL database, which is collated to utf8_general_ci and the characters show correctly via phpmyadmin.

    4. I select it and output results and it shows as boxes. Only the English/latin characters display (not with accents though). I assume I don't have to convert to keyboard codes- that if encoding is UTF8, font is correct, and data is correct that it should display.


    Anyone know what I'm missing on how to display UTF-8 chars?
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    1. Only one of those is actually necessary though it doesn't hurt to do both. I personally prefer putting the character set in the output, like a META tag for HTML.

    2. There is no font that has everything, but the most common fonts have a lot. Bring up a character list by font (such as Windows' charmap.exe) and see if it includes the characters you want.

    4. Sounds like you're doing everything right but there's clearly a problem. Is there somewhere you can show us?
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    In the PHP forum, FAQ #29 covers this subject. A lot of it discusses things you've done already, but it is worth reading anyway, particularly if your UTF-8 content is coming from a MySQL database through PHP.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo