PHP and UTF-8 Woes

Do you find yourself working with foreign characters and they go all screwy when you use forms or your MySQL database? You could have UTF-8 issues.

If you are unsure what UTF-8 is and why it is important, here’s a great resource where you can find out more, but let’s assume you know your  characters but need a solution for working with them using PHP, MySQL and forms.

Firstly, have you ensured your pdo database connection is using UTF-8 because that is the most likely cause (assuming you are using that, right? If not, please adapt):

The important parts are the options with the array. That’s one solution if you are using PHP < 5.3.6 but newer than that, this is preferable:

Here, the difference is the charset part.

That should have fixed it but if not, here are a couple of other things you really ought to be doing anyway.

Find your PHP.ini file and ensure that the following line is set:

One last thing coming up! In all your HTML files, ensure you have the following in your head section:

Happy charactering 🙂


Written by Stephen Moon
email: stephen at

Hey! Did you enjoy reading this? If you did and would like an email when I add new content, just subscribe to my list. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *