Strange character in fresh WAMP installation?

落爺英雄遲暮 提交于 2019-12-20 07:29:32

问题


I'm getting strange characters in my fresh local WAMP installation. I've just downloaded all .php files from ftp online and restored a backup on my local mysql server. The problem only happens when text contains symbols or special characters:

PHP: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

MySQL collation: latin1_swedish_ci

In this image of course there is a strange symbol "°" where "°" and "€" are needed. This has happened both in Opera and Firefox.

Any idea? Thanks for helping, as always.


回答1:


I'll answer here because it's too long for a comment.

You don't need to change your encoding, you should check your encoding. Keep in mind that encoding could be changed in a lot of different places:

  • In your database with charset functions
  • In your apache configuration with AddDefaultCharset
  • With php header function
  • In your html with a <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> tag

Any of these reasons could lead to wrong encoding displayed in the web browser. And if you do not specify it with one or more the previous methods, the corresponding layer will use its configured default.

In your case since the text is coming from database and since often in WAMP/XAAMP/MAMP MySQL use a weird default encoding, I'd check for point one. Try to execute SET NAMES UTF-8 (or whatever encoding you use) query before retrieving data, just after your db connect function.



来源:https://stackoverflow.com/questions/7522956/strange-character-in-fresh-wamp-installation

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