-->

problem with special characters

2020-04-23 04:22发布

问题:

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:

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.



回答2:

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