Don't put HTML-encoded data in the database. It should be raw text until the time you spit it onto the page (at which point you should use htmlspecialchars()
.
You need to make sure that both your database and your page are using UTF-8:
- ensure your tables are CREATEd with a UTF-8 collation;
- use mysql_set_charset after connecting to ensure the connection between MySQL and PHP is UTF-8;
- set the
Content-Type
of the page to text/html;charset=utf-8
by header or meta tag.
You can get away with using a different encoding such as the default latin-1 on the database end and the connection if you treat it as bytes, but case-insensitive comparisons won't work if you do, so it's best to stick to UTF-8.