SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast mitsy's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mysql and utf-8 characters

    i have a little problem,

    when i run my php script which takes a string from mysql, i see squares instead of the un-latin characters.

    for example:
    in the database there is "Beyoncé" entered.
    but the php script is printing "beyonc" and a square instead of "é"

    1) i use header ('Content-type: text/html; charset=utf-8'); in the script
    2) and in mysql table, the row is "utf8_unicode_ci" encoded.
    3) and also i use <META http-equiv='Content-Type' content='text/html; charset=utf-8'> meta tag in the output.

    so how can i fix it? i think the solution is simple but i couldn't succeed with hours of internet research

    PS. if i use this:
    echo"Beyoncé";
    this outputs the correct form "Beyoncé".
    but i dont want it, i want to do
    echo"Beyoncé";

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mitsy -

    you may want to try making the entire table utf8:

    CREATE TABLE tablename (
    ...

    ) DEFAULT CHARACTER SET utf8;

    For good measure, make sure your editor is encoded utf8 - not just in the output script.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Hobart, Australia
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the iso-8859-1 character set.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,027
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by swto View Post
    Hi Mitsy -

    you may want to try making the entire table utf8:

    CREATE TABLE tablename (
    ...

    ) DEFAULT CHARACTER SET utf8;

    For good measure, make sure your editor is encoded utf8 - not just in the output script.
    And the very next line after to connect to the database (assuming your using MySQL) add:
    PHP Code:
    mysql_set_charset('utf8',$link_id); 
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Hobart, Australia
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    And the very next line after to connect to the database (assuming your using MySQL) add:
    PHP Code:
    mysql_set_charset('utf8',$link_id); 
    Can you make the client connection default to utf-8 either through PHP or MySQL configs?

  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mitsy, the answer as simple, as just one line after mysql_connect():
    PHP Code:
    mysql_query("SET NAMES utf8"); 
    And everything will be ok.

    Client already using iso-8859-1 by default, so, no need to set it, need to overwrite it instead.

    SET NAMES is preferred and useful way among setting encoding. Works everythere.


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
  •