Trouble with Character Encodings

(This is work in progress.)

It seems the easiest thing to do is to keep everything in UTF-8:

<?php
header("Content-type: text/html; charset=UTF-8");
?>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

If you don’t want to use UTF-8 but stick with, say, ISO-8859-1 because you already have a database encoded in latin1, you can surely do so. The above points apply to this character sets as well. I had trouble, however, when moving a database to a new server. Make sure all files are exported and imported with the same encoding (could be UTF-8 as well). If you’re still having problems, check which character set is used when your PHP script connects to MySQL because sometimes it’s not the one you want. If that’s the root of your problems, you can simply do this:

<?php
mysql_query("SET CHARACTER SET 'latin1'");
?>