How to properly display Chinese characters in PHP?

Look that your file is in UTF8 without BOM and that your webserver deliver your site in UTF-8

HTML:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

in PHP:

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

And if you work with a database look that your database is in UTF-8 if you read the text from your database.


Simple:

  1. save your source code in UTF-8
  2. output an HTTP header to specify to your browser that it should interpret the page using UTF-8:

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

Done.

utf8_encode is for converting Latin-1 encoded strings to UTF-8. You don't need it.

For more details, see Handling Unicode Front To Back In A Web App.


$chinesevarOK = mb_convert_encoding($chinesevar, 'HTML-ENTITIES', 'UTF-8');

Tags:

Php