PHP Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.21

Non ASCII Characters as String Literals

Part:   1  2  3  4  5 

PHP Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Non ASCII Characters with MySQL

Inputting Non ASCII Characters

Controlling Response Header Lines

HTTP Request Variables

Sessions

Using Cookies

PHP SOAP Extension

PHP SOAP Extension - Server

Directories, Files and Images

Using MySQL with PHP

... Table of Contents

(Continued from previous part...)

3. To enter the French character, "e with grave", you can run Start > All Programs > System Tools > Character Map. Select "e with grave" on the character map. Click the Select button, then the Copy button. Go back to your Notepad and click Ctrl-V to paste "e wtih grave" into your PHP script.

4. Select menu File > Save as. Enter the file name as HelpIsoFrench.php. Select "ANSI" in the Encoding field and click the Save button. Note that ANSI is encoding schema defined by Microsoft and used on Windows system. ANSI contains more characters than ISO-8859-1. But it is compatible with ISO-8859-1.

5. Copy HelpIsoFrench.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/HelpIsoFrench.php. Your should see the French characters displayed correctly as shown below:

Help
English: System load is very high.
French: L'utilisation de système est très haute.

7. On the IE window, select menu View > Encoding. You should see "Western European" is selected. Again "Western European" is a different name for ISO-8859-1.

Easy to do, right? We could make it even easier. You can remove the <meta> tag setting in HelpIsoFrench.html. French characrters will still show up on the IE window. This is because ISO-8859-1 is the default encoding schema to IE.

Chinese Characters in String Literals - UTF-8 Encoding

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) 2005 by Dr. Herong Yang, http://www.herongyang.com/
#
   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>');
?>

When I copy this HTML document into this book, I have to replace all UTF-8 encoded Chinese characters with "?"s, because my book is written in HTML document with the default encoding schema. To follow my tutorial, just enter any Chinese character whenever you see "?".

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.

(Continued on next part...)

Part:   1  2  3  4  5 

Dr. Herong Yang, updated in 2006
PHP Tutorials - Herong's Tutorial Notes - Non ASCII Characters as String Literals