I'm working on a French language site built in CakePHP. I have tried multiple functions to try and convert the text into UTF-8 and display properly, but have had no success so far - any accented letters are displaying as a black diamond with a question mark. They do display correctly when I change the char set in the browser to ISO-8859-1, but I'd like to make the while site UTF-8 compliant. I have used:
html_entity_decode($string, ENT_QUOTES, 'UTF-8'); htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); utf8_encode
but no cigar. The page is set to UTF-8 in the header
And the MySQL database is using UTF-8 too. How can I get the accented characters to display properly in UTF-8?
First: Check your php files encoding! I work on Mac, I use Coda to program, and it has an option to convert charset's, sometimes i get troubles like this and converting to UTF-8 always fix them. I think that Notepad++ can do that on windows. (If you do this on your PHP files, every strings on them will not need the functions
htmlspecialchars()
,html_entity_decode
, etc )Second: if you are using HTML Output, check if you have
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
on your header...Third: Do what @janmoesen said on your MySQL DB.
Tell me something about that.
Check your
@@character_set_results
. By default, MySQL useslatin1
, notutf8
. TrySET NAMES utf8
or mysqli::set_charset.Update: here is how you might check the character sets in use:
Read more on dev.mysql.com.
I just fixed a very similar problem with accented characters not displaying. My database table is utf-8 encoded and my html header is correctly set for utf-8.
I hadn't specified a charset for my MySQL connection, in my case I'm using PDO.
No problems now!
In case this helps anyone using PHP Classes.
My solution was to set Character Encoding to my Connection.