PHP Tutorials - Herong's Tutorial Examples - Version 4.17, by Dr. Herong Yang
Characters of Multiple Languages in String Literals
This section provides a tutorial example on how enter and use characters of multiple languages in a single PHP script with Unicode UTF-8 encoding.
After going through the above examples, you should feel comfortable now on how to handle non-ASCII characters of any single language. You have a choice of using UTF-8 or a language specific encoding.
If you want to have characters of multiple languages in a single PHP script, then you have to use UTF-8 encoding. Here are the steps you can follow make a PHP script in UTF-8 for a number of languages.
1. On a Windows system, run Start > All Programs > Accessories > Notepad.
2. In Notepad, enter the following PHP script:
<?php #HelpUtf8MultiLanguages.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>Test</b><br/>'); print('English: Hello world!<br/>'); print('Spanish: ¡Hola mundo!<br/>'); print('Korean: 여보세요 세계 !<br/>'); print('Chinese: 你好世界!<br/>'); print('</body>'); print('</html>'); ?>
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.
Last update: 2015.
Table of Contents