Setting UTF-encoding with a PHP header

Sometimes, I need to write a one-off PHP script to export/import data from a database, for example. Since I am not using any kind of front-end interface, I have found that I sometimes have to specifically set the encoding on the page to avoid any extended character issues with the database. I use:

header('Content-Type: text/html; charset=utf-8');

And that seems to work just fine.

Leave a comment

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