问题
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