|
Non ASCII Characters as String Literals
Part:
1
2
3
4
5
(Continued from previous part...)
French Characters in String Literals - UTF-8 Encoding
First, let's play to some French characters in UTF-8 encoding first.
1. On a Windows system, run Start > All Programs > Accessories > Notepad.
2. In Notepad, enter the following PHP script:
<?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>Help</b><br/>');
print('English: System load is very high.<br/>');
print('French: L\'utilisation de système est très haute.<br/>');
print('</body>');
print('</html>');
?>
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 with grave" into your PHP script.
4. Select menu File > Save as. Enter the file name as HelpUtf8French.php. Select "UTF-8"
in the Encoding field and click the Save button.
5. Copy HelpUtf8French.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/HelpUtf8French.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 UTF-8 is selected.
Another interesting thing you should know is about how Notepad stores a UTF-8 file. When you use UTF-8
encoding to store a file in Notepad, it will insert a UTF-8 marker (3 bytes) at the beginning of the file.
Use the "type" command in a command window, you will see this:
>type HelpUtf8French.php
n++<?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>Help</b><br/>');
print('English: System load is very high.<br/>');
print('French: L\'utilisation de syst+¿me est tr+¿s haute.<br/>');
print('</body>');
print('</html>');
?>
The hex value of the UTF-8 marker is 0xEFBBBF. IIS server will send it the client. IE browser will not show it
on the page, but it will use it to detect the encoding schema, if needed. Not sure on how other browsers will behave
this marker.
Working, right?
French Characters in String Literals - ISO-8859-1 Encoding
Now we know how to make French characters working in a PHP string literal in UTF-8 encoding schema.
Next let's see how to them working in ISO-8859-1 encoding schema.
1. On a Windows system, run Start > All Programs > Accessories > Notepad.
2. In Notepad, enter the following PHP script:
<?php #HelpIsoFrench.php
# Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/
#
print('<html>');
print('<meta http-equiv="Content-Type"'.
' content="text/html; charset=iso-8859-1"/>');
print('<body>');
print('<b>Help</b><br/>');
print('English: System load is very high.<br/>');
print('French: L\'utilisation de système est très haute.<br/>');
print('</body>');
print('</html>');
?>
(Continued on next part...)
Part:
1
2
3
4
5
|