Jump to content

[SOLVED] Trouble working with UTF-8 Characters


lonelycastle

Recommended Posts

Alright, so I have a mysql database full of location names from around the world.  Needless to say, there's a lot of unusual characters.  The database and each table within it has a utf8_general_ci collation and all the rows appear fine within the database:

 

Examples:

Nichiyō Seamount

嫁島海山

Kobilovača

Bom Princípio do Piauí

 

I have this in the header: <meta http-equiv="content-type" content="text/html; charset=UTF-8">

And I utf8_encode all the info I get from the database: utf8_encode($qry[title]);

 

This works for basic symbols:

Bom Princípio do Piauí
Cidelândia
São José da Safira

 

But not for some of the more complex ones:

?uri?a Staje (should be Ćurića Staje)
???? (should be سوت)
Gy?ja-zan (should be Gyōja-zan)

 

I know very little about character encoding or how to make sure everything (especially the communication between the database and website) is using utf8.  Any help you could offer would be great.  Thanks.

 

 

Link to comment
Share on other sites

Hi

 

I'm not sure why some characters are working and not others. My db and my html are in utf-8 and i dont use utf8_encode() function - and all non-latin including Chinese and Arabic shows fine

 

One suggestion which could just be plain silly, is to change the font your are outputting the data in. That may have an effect?

 

Cheers,

tdw

Link to comment
Share on other sites

To reiterate, have you tried using SET CHARACTER SET charset_name when connecting to MySQL?

 

I don't know much about how to change the MySQL connection.  My brother usually does that stuff, but he's at class at the moment.  If you could tell me what to look for [what the connection code looks like] I could try and figure it out.

 

Which looks more like the connecting code:

 

$CONNECT_SLAVE = myC("SLAVE");
$CONNECT_MASTER = myC("MASTER");

.. both of which go to a function which does this:

$link_identifier = mysql_connect($_DB[$server_group][$r]['IP'], $_DB[$server_group][$r]['USER'], $_DB[$server_group][$r]['PASS']) or error_mysql("Connect - ".$_DB[$server_group][$r]['PASS']);

 

or

 

mysql_query("USE `".$database."`", $link_identifier) or error_mysql("USE `".$database."`");

 

or

 

$resource = mysql_query("$query", $link_identifier) or error_mysql($query);

 

I know I'm an idiot, but thanks for the help.

 

 

Link to comment
Share on other sites

As long as the form knows you're using UTF-8 via the meta tag, and MySQL knows you're using UTF-8 via SET CHARACTER SET, everything should be transparent.

 

This is how I understand it: A user types/pastes "¶" into your form and submits. The submitted data is now "¶", the UTF-8 encoding for "¶", because your meta tag said use UTF-8. When you connect to MySQL you instruct it to use UTF-8, and since your data is already there, you simply drop it in. The same applies when pulling data out. You tell MySQL to use UTF-8, it gives you UTF-8, and you tell the browser to render UTF-8, and it does so.

Link to comment
Share on other sites

  • 3 years later...

After you've connected to MySQL, try running these:

 

    mysql_query("SET CHARACTER SET utf8");

    mysql_query("SET NAMES utf8");

 

This solution helped me too, but, what about text that does not come from db but from the php/html file? After i applied the solution you suggested, was resolved the apparition of non-latin letters that comes from the db but not the letter that comes from the file.

Thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.