Strange characters from the MySQL PHP database

advertisements

I'm trying to output product information stored in a MySQL database, but it's writing out some strange characters, like a diamond with a question mark inside of it.

I think it may be an encoding/UTF8 issue, but I've specified the encoding I want:

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

Is this right? What should I check for?


If only the data that's coming from database has strange characters in it, be sure that the MySQL connection is also in UTF8 by using:

mysql_query("SET NAMES UTF8");

before any other queries. Otherwise, if the characters appear also in 'handwritten' files, make sure that the files are saved as UTF-8 in your editor. You can also try setting the charset header through PHP:

header('Content-type: text/html; charset=UTF-8');

Also make sure that all fields in the tables you are querying are set as some UTF-8 variant, for example utf8_general_ci.