开发者

MySQL collation and PHP charset conflict

I have a bunch of Danish text taken from a latin-1 MySQL database and it displays correctly when echoed in PHP. The problem starts when I need to echo some other Danish characters, which are not taken from t开发者_开发问答he database.

What I do is actually output the header

Content-Type: text/html; charset=iso-8859-1

to also let the non-queried characters to display correctly as well.

Problems is, when I do that the queried characters display incorrectly.


Just because the data is stored in a latin-1 collated table doesn't mean that it's latin-1 encoded. This is due to MySQL not doing any character translation when the connection SET NAMES setting is the same as the collation.

I suspect that you have some UTF8 characters stored in a latin1 database which is confusing the issue.

For more help please can you add details of the:

  • MySQL connection encoding that you have set
  • Details of where the "non-queried" characters are coming from


Use unicode. UTF-8 => the right way.

So, set utf8_unicode_ci in database, UTF-8 as page charset and before your query set mysql_query("SET NAMES UTF8");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜