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:

#  HelpUtf8MultiLanguages.php
#- Copyright (c) All Rights Reserved.
   print('<meta http-equiv="Content-Type"'.
      ' content="text/html; charset=utf-8"/>');
   print('English: Hello world!<br/>');
   print('Spanish: ¡Hola mundo!<br/>');
   print('Korean: 여보세요 세계 !<br/>');
   print('Chinese: 你好世界!<br/>');

3. Don't try to enter those hello messages yourself. Go to the Google language tool site, 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:\apache\htdocs. 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.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.3

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 Managing File Upload

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

Using Non-ASCII Characters as PHP Script String Literals

 Basic Rules of Using Non-ASCII Characters in HTML Documents

 French Characters in String Literals - UTF-8 Encoding

 French Characters in HTML Documents - ISO-8859-1 Encoding

 Chinese Characters in String Literals - UTF-8 Encoding

 Chinese Characters in String Literals - GB2312 Encoding

Characters of Multiple Languages in String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Parsing and Managing HTML Documents

 Configuring and Sending out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Outdated Tutorials


 Full Version in PDF/EPUB