Tag Archives: utf8

PHP, MySQL and utf-8

When creating forms with french content, I got strange characters in my database.
The solution was to put some utf-8 declaration at the top of the php pages and to add some extra code for mysql.

php:

<?
php header(‘content-type: text/html; charset: utf-8′);
mb_internal_encoding( ‘UTF-8′ );
?>

MySQL:
add the following code after you make a connection and before you run a query
mysql_query(“SET NAMES ‘utf8′”);
mysql_query(“SET CHARACTER SET utf8″);

Additionally you could also add accept-charset=”utf-8″ to your form tags.