I am retrieving articles from my blog to my webiste from the mysqlDb. The articles are displayed just fine on the blog but on the website some characters such as ţ,ş,ă etc are replaced with a black square with a question mark inside . I have "UTF-8" set on my document the same as on the blog.
+1
A:
How did you add these characters into the document? Depending on the editor the encoding can be skewed when saving. Did you set the document type in HEAD using META in addition to specifying the encoding using PHP headers?
Here is some further reading on the subject http://htmlpurifier.org/docs/enduser-utf8.html
methodin
2010-10-07 13:09:38
+2
A:
You need to tell to MySQL that the connection must be made in UTF-8. To do so use the function mysql_set_charset (you need PHP 5.2.3). If you use PHP < 5.2.3 try :
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);
Also make sure the headers tells that the document is in UTF-8 (header function and/or HTML meta tags correctly set).
Also make sure your PHP files are saved in UTF-8 without a BOM.
AlexV
2010-10-07 13:24:57
mysql_set_charset() it was!Thanks a lot!
andrei
2010-10-07 13:32:12
Yeah it's a common pitfall. If you don't do this MySQL will convert the data on the fly to latin1 (equivalent of utf8_decode).
AlexV
2010-10-07 13:33:48