SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict Mr Jojo's Avatar
    Join Date
    May 2007
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DB returns data in UTF-8

    I have my php site coded in ISO, but since i changed my website to online servers the database returns the data in UTF-8, and the page is coded in ISO.

    How can i solve this DB problem?
    I changed every table to Latin1, nothing happened.

    If i cant solve it this way, how can i change my PHP files to unicode (UTF-8)?

    Thanks!

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ISO what? Anyways, to set your output charset use:

    Code php:
    header('Content-type: text/html; charset=UTF-8');
    Saul

  3. #3
    SitePoint Addict Mr Jojo's Avatar
    Join Date
    May 2007
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That dont solve the problem, because the page is formated as ISO, so decoding as UTF-8 words like "mão" will stay "m?o".

    The problem is that, the database returns data in UTF-8, but the page is coded in ISO.
    So, when i put that header you gave me, the DB data will appear correctly in the page, but the page's data will appear like "m?o".

    How can i change the collation of the php files?

    Thanks!

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Location
    edge of nowhere
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to also add the charset info to your templates.


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    Programming boils down to three things: fast, good and cheap.
    Please pick two.

  5. #5
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nah...all this doesn't work out if the template itself is still coded in ISO.

    @Mr Jojo: best way to go is to remove all special chars and replace them with there entities.
    e.g.: &#228; will then be &#228; - this is the same in ISO and UTF8 so you won't see weird signs.
    You could also try using "set names" with your database - send this query before selecting anything from your database: "SET NAMES 'ISO-8859-1'"

  6. #6
    SitePoint Addict Mr Jojo's Avatar
    Join Date
    May 2007
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol.
    That will give lots of work :P

    Isnt there any program that makes that conversation? I make my websites in editplus, does he can do that?

    Thanks!

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Location
    edge of nowhere
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    G. Schuster is absolutely right. You also need to change each character to their correspondent in the respective charset, unless yoour editor had a bug that already placed them that way mistakenly (you will have to try and see).

    [offtopic]
    G. Schuster, are you in any way connected to Gerhard Schuster Automobile of Munchen/Passau?
    The name is strikingly similar.
    [/offtopic]
    Programming boils down to three things: fast, good and cheap.
    Please pick two.

  8. #8
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @sebulbus: sorry, nobody in my family works in the automobile sector.

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure that it's the database, which returns UTF-8 encoded data? If you view the page in Firefox, and go to menu View > Character Encoding, which charset is selected?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •