字符编码 - 我不明白

Okay, I don't really get character encoding at all and I'm doing research on it, but I was hoping someone could explain to me what's going on here.

In my products table, I have descriptions. In phpMyadmin, it looks like this:enter image description here

I've set the encoding (just today) to utf8_general_ci. Good.

Now in the pLongDescription on one of my products, I have this:

enter image description here

You see that there? That's some dodgy apostrophe that Word or something uses. It continually creeps in to my life. I can't even type it on my keyboard into anything other than word. I much prefere to use ' instead.

Anyway, I would have thought with the utf8_general_ci set, it wouldnt be a problem. If I output this normally from the database through PHP, I get this:

enter image description here

However, If I use utf8_encode($pDescription) I get this:

enter image description here

Neither of them are perfect. On on hand, i've got a bunch of horrible errors. On the other, I've got bad grammer and spelling because it's missed out the apostrophe's in the description.

What is happening here and how can I fix it?

mysql_query('SET CHARACTER SET "utf8"');
mysql_query('SET NAMES "utf8"');
ini_set('default_charset', 'UTF-8');

use this:) that help me

put this after connection of mysql

and if you are using html, don`t forget to set charset: meta charset="utf-8"

Try with this :

$pDescription = mb_convert_encoding ($pDescription, "UTF-8", "UTF-8");

Don't forget to aactivate this extension extension=php_mbstring.dll in your php.ini and restart your Web Server

Hope that Helps :)

You are mixing up concepts. What you are seeing is "collation", which indicates how it would sort data. Encoding is set at table level, with DEFAULT CHARSET=utf8 (or preferred charset) when you create the table. (it can be set as a global default in my.ini/my.cnf as well)

Then, you need to instruct each connection that it is a utf8 connection, by invoking SET NAMES utf8 (or mysql_set_charset('utf8', $link);) first hand for each connection you make.

From now on, when you read out data, and output with PHP, it will send a utf8 bytestream to the browser. Assuming that you have instructed the browser to decode it has utf8 by setting relevant content-type headers or similar, this would work.

If you have any hard coded text in your PHP files that utilizes extended characters, the PHP file must also be saved as utf8, so it matches the output from the DB (otherwise you will render mixed encodings on your pages).

There are more things to consider, one suggestion is this article:

http://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql