|
Non ASCII Characters as String Literals
Part:
1
2
3
4
5
(Continued from previous part...)
3. Don't try to enter those hello messages yourself. Go to the Google language tool site,
http://www.google.com/language_tools. You can enter "Hello world!" and translate it to other languages.
On the translation output page, just copy those translations and paste them back to Notepad.
This should cause no corruption, because Google site, Windows IE, and Notepad all support UTF-8.
4. Select menu File > Save as. Enter the file name as HelloUtf8MultiLanguages.php. Select "UTF-8"
in the Encoding field and click the Save button.
5. Copy HelloUtf8MultiLanguages.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/HelloUtf8MultiLanguages.php.
Your should see all characters displayed correctly.
7. On the IE window, select menu View > Encoding. You should see UTF-8 is selected.
Conclusion
- PHP string data type is defined as sequences of bytes.
- PHP string literal can almost non ASCII characters in almost any encoding schema.
- The best choice of encoding schema is UTF-8.
- Using UTF-8 encoding in PHP scripts requires a good UTF-8 compatible editor.
- PHP script generates HTML document using print() function, which is a byte stream output function,
offers no encoding conversion by default.
Part:
1
2
3
4
5
|