problem with special characters

旧街凉风 提交于 2019-12-02 12:56:19

问题


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



来源:https://stackoverflow.com/questions/3881911/problem-with-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!