How to properly display Chinese characters in PHP?

前端 未结 5 2012
清酒与你
清酒与你 2020-12-04 01:39

I have these Chinese characters:

汉字/漢字\'\'test

If I do

echo utf8_encode($chinesevar);

it displays

<
5条回答
  •  清歌不尽
    2020-12-04 02:01

    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.

提交回复
热议问题