How to best configure PHP to handle a UTF-8 website

Viewed 61401

What extensions would you recommend and how should php be best configured to create a website that uses utf-8 encoding for everything. eg...

  • Page output is utf-8
  • forms submit data encoded in utf-8
  • internal processing of string data (eg when talking to a database) are all in utf-8 as well.

It seems that php does not really cope well with multibyte character sets at the moment. So far I have worked out that mbstring looks like an important extension.

Is it worth the hassle..?

6 Answers

2018 Update :::

Kindly note that these php.ini entries are DEPRECATED;

;mbstring.internal_encoding = utf-8
;mbstring.http_input =
;mbstring.http_output = utf-8

Next ...

PHP - Set utf8 for the following - via a config.php file for your web app

 ini_set('default_charset', 'UTF-8');                                    
 mb_internal_encoding('UTF-8');
 iconv_set_encoding('internal_encoding', 'UTF-8');
 iconv_set_encoding('output_encoding', 'UTF-8');

MariaDB / MySQL - Set utf8 via:

 mysqli::set_charset ( "utf8mb4" );

HTML Pages - Set via:

 <meta charset="utf-8" > 
Related