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.
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…
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
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.
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.
Mark’s comment worked for me and my annoying french accents! Thanks guys. You just submit the query ‘SET NAMES utf8′ prior to submitting your funny characters.
thanx for help it is helpful discussion
This is your solution
http://phpanswer.com/store-french-characters-into-mysql-db-and-display/
————-
use mysql_set_charset(‘utf8′, $database_connection);
Hi There! I have a big problem!…
I have an Excel 2007 (PC) file in and I export it to CSV to import it in MySQL.
The export from Excel 2007 to CSV does not allow me to choose any charset, I think it export it in cp2150 but not sure.
Then I use:
mysqli_query($con,”LOAD DATA LOCAL INFILE ‘$path’ INTO TABLE $table
CHARACTER SET ‘cp1250′…
But I o not see right the inverted french accents…
Have tried:
- $wine = iconv(‘ISO-8859-1′,’UTF-8′,$wine);
- mysqli_query($con,”SET NAMES ‘utf8′”);
- mysqli_set_charset($con, “utf8″);
-
And all convinations… But I am… Desperate!!!
THANK YOU!!!