Jump to content

Internationalization: characters don't display as they are in DB


LLLLLLL

Recommended Posts

I have a MySQL DB table and DB column with utf8_unicode_ci collation. I'm getting two columns out of the DB, one with the name of a language in English, the other a name of the language in the native tongue. The values in the database store/display properly from PHP MyAdmin.

 

However, the "native-tongue" text does not display properly on the site. (See attached image.)

 

I tried htmlentities( $str, ENT_COMPAT, 'UTF-8' ) for displaying, but that seems to make things worse (French, Portuguese, Spanish, and Turkish all display as empty; something I have not seen before).

 

I thought that the htmlentities function should cure this, but since it does not, I am stumped. Any help is appreciated.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Hi, I'm still looking for an answer to this. Here is more information:

  • I copied the text français into a database upgrade file (text file)
  • That text got inserted into the DB as Français. (When I view the data in phpMyAdmin)
  • The text must have saved that way in the text file, too (when did it change?)
  • This text DOES now display as français

 

So should I be happy that it displays correctly? Should I not care how phpMyAdmin displays it?  Sigh, so complicated

 

Link to comment
Share on other sites

Your issue is most likely the one described in this great blog post:  http://omegadelta.net/2010/11/23/when-you-thought-the-db-was-utf-8-but-it-wasnt/

 

MySQL is not alone in having a default character set for the client library.  You want this to be correct end to end, but if you don't explicitly tell mysql that you want the client switch to utf8, otherwise it will use whatever the default is, which is often latin1.  This is such a common problem that they recently added mysql_set_charset and that page has notes on the previous methods of handling this.  I'm guessing here that you have a mismatch and that your application probably does not set the client character set for your mysql connections.

Link to comment
Share on other sites

I understand what you're saying here, and I will take a look at making these changes. However, I am still unable to explain that third bullet point above, as it has nothing to do with the database. In short:

1) I copied français into a text file and saved it.

2) When I edited the text file again, it had the jibberish text.

 

Wassup with that? I'm using cPanel to do these "saves", and its encoding is indeed utf-8

Link to comment
Share on other sites

Per my last entry, I didn't actually have the right encoding set for the file. So that's why it didn't work.

 

Per the overall topic, the solution was to add mysql_set_charset(), as you suggested.

 

Bravo. My shopping cart just got better!

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.