Different character encoding stored in my database
I've got a nasty character encoding problem and looking for ideas on how to solve it.
I've maintained a database for the past years in latin1_swedish_ci format. Everything worked just fine. When checking varchars in PHPMyAdmin I could see accents like ë and on the front-end they displayed correctly.
Now recently I switched my app开发者_开发技巧lication over to UTF-8. I've also set my HTML page's character encoding to UTF-8 but not my database. Problems started to surface. Sometimes characters where encoded correctly, sometimes not.
The reality is, varchars stored recently appear fine, old varchars (prior to switching to UTF-8) display as black squares. If I switch my page's character encoding to ISO8859-1 the opposite happens. Old special characters display fine, new special characters display as black squares.
So the reality is that my database is storing special characters different than before. How can I clean up this mess without breaking things?
You can try something like:
$string = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $string);
or
$string = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $string);
And see if the encoded character change over.
精彩评论