PHP, MySQL and UTF-8

The following code changes the default encoding of PHP (one of ISO encodings in most cases) to work properly with UTF-8 encoding of the database.

<?php

/**
 * http://www.polak.ro/php-mysql-utf-8.html
 *
 * The following code forces most of PHP configurations 
 * to work properly with MySQL and UTF-8 encoding
 */

ini_set( 'mbstring.language',          'UTF-8' );
ini_set( 'mbstring.internal_encoding', 'UTF-8' );
ini_set( 'mbstring.http_input',        'UTF-8' );
ini_set( 'mbstring.http_output',       'UTF-8' );
ini_set( 'mbstring.detect_order',      'auto' );
header ( 'Content-type: text/html; charset=UTF-8' );

?>

The ini_set function must be allowed by PHP configuration, it will not work under safe mode.

Powered by PepisCMS