French Characters Not Rendering Correctly
Background Knowledge
The MySQL database v4.0.23 is using the default character set of “Latin1″. When the database was created I had no knowledge of character sets other wise it would have been “UTF-8″.
The web pages are using a character set of “UTF-8″.
Problem
Data being queried from a MySQL database that contains French accent characters will not render correctly in the browser even after applying PHP htmlentities().
Example code: $string = htmlentities($string , ENT_QUOTES, “UTF-8″);
Solution
The queried data from the database was inputted using the character set “ISO-8859-1″. I found this out by changing the browser’s character encoding to “Western ISO-8859-1″ and the French accent characters then rendered properly. With the use of PHP iconv() I was able to convert the data from “ISO-8859-1″ to “UTF-8″ character set and the French characters then rendered properly in the browser.
Example code: $string = iconv(”ISO-8859-1″,”UTF-8″,”$string”);
If you are unaware of what MySQL default character set being used, you can run this SQL command “show variables like “%character%” and check your MySQL configuration file. Refer to the MySQL manual for further details.


November 16th, 2007 at 3:31 pm
what i’ve realized is that no matter what column type (latin1, utf-8) in mysql, if the browser’s meta tag is set to utf-8, it will encode it on input and on output.
of course, if you wanted to do anything specific with the data outside of a browser, you’d probably run in to trouble though. but otherwise mysql appears to treat it just like normal binary data and there’s no special treatment needed in PHP or MySQL…
November 19th, 2007 at 2:58 pm
You would probably find it easier, and it would be more correct, to set the database’s client connection encoding to utf8 instead of using iconv() in PHP.
Just do “SET NAMES utf8″ after connecting each time.
Mark
November 20th, 2007 at 11:50 am
Re: Mike
Yes I would agree it does do that and rightfully it should as you have specified specifically to use a character encoding set in the meta tags.
November 20th, 2007 at 11:53 am
Re: Mark
I would entirely agree Mark. However I’m using MySQL v4.0.23 and that statement will not work. My assumptions are that proper support for character encoding was not supported until v4.1. I was unable to find anyone to help me further on this with the version I have installed. I would definitely upgrade if I could.