PHP Tutorials - Herong's Tutorial Examples - Version 4.17, by Dr. Herong Yang
Chinese Characters in String Literals - UTF-8 Encoding
This section provides a tutorial example on how enter and use Chinese characters PHP string literals using Unicode UTF-8 encoding. The PHP script file should be stored in UTF-8 format.
Now let's play with Chinese characters. They are definitely harder to work with than French characters. My first example shows you how to handle Chinese characters in PHP scripts with UTF-8 encoding.
1. On a Windows system, run Start > All Programs > Accessories > Notepad.
2. In Notepad, enter the following HTML document:
<?php #HelpUtf8French.php #- Copyright (c) 2015, HerongYang.com, All Rights Reserved. # print('<html>'); print('<meta http-equiv="Content-Type"'. ' content="text/html; charset=utf-8"/>'); print('<body>'); print('<b>说明</b><br/>'); print('这是一份非常间单的说明书…<br/>'); print('</body>'); print('</html>'); ?>
3. As I mentioned earlier in this book, entering Chinese characters is not an easy job. You need to use a Chinese Windows system, or a Chinese input tool on a non-Chinese Windows system. If you don't have any Chinese input tool, you can simply go to the Yahoo Chinese Web site, http://www.yahoo.com.cn/, copy some Chinese characters, and paste them into Notepad. The Yahoo Chinese Web site is encoded in UTF-8.
4. Select menu File > Save as. Enter the file name as HelpUtf8Chinese.php. Select "UTF-8" in the Encoding field and click the Save button.
5. Copy HelpUtf8Chinese.php to c:\inetpub\wwwroot. Make sure your Internet Information Service is running the local default Web site.
6. Now run Internet Explorer (IE) with http://localhost/HelpUtf8Chinese.php. Your should see the Chinese characters displayed correctly.
7. On the IE window, select menu View > Encoding. You should see UTF-8 is selected.
Last update: 2015.
Table of Contents