Chinese Characters in String Literals - GB2312 Encoding

This section provides a tutorial example on how enter and use Chinese characters PHP string literals using GB2312 encoding. The PHP script file should be stored in GB2312 format.

I think we are ready to test Chinese characters in PHP scripts with GB2312 encoding schema now.

1. This time, we can not use Notepad, because Notepad is not compatible with GB2312 encoding. It will actually convert GB2312 encoding to UTF-8 encoding. So don't use Notepad.

You need to go get another text editor, like Jext, to help you enter the Chinese characters in GB2312 encoding.

2. In a good text editor, enter the following HTML document:

<?php
#  HelpGb2312Chinese.php
#- Copyright 2009 (c) HerongYang.com. All Rights Reserved.
#
   print('<html>');
   print('<meta http-equiv="Content-Type"'.
      'content="text/html; charset=gb2312"/>');
   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 GB2312 encoded Chinese characters with "?"s, because my book is written in HTML document with UTF-8 encoding schema. To follow my tutorial, just enter any Chinese character whenever you see "?".

3. Entering Chinese characters in GB2312 encoding also requires some Chinese input tools. If you don't have any Chinese input tool, you can simply go to my GB2312 page, https://www.herongyang.com/gb2312_gb/, open the source code of the page, copy some Chinese characters, and paste them into the editor. My GB2312 page is encoded in GB2312. Warning, do not copy Chinese characters from the IE browser window. The browser window copy function is assuming UTF-8 encoding and will corrupt the copied characters.

4. Select menu File > Save as. Enter the file name as HelpGb2312Chinese.php and click the Save button.

5. Copy HelpGb2312Chinese.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/HelpGb2312Chinese.php. Your should see the Chinese characters displayed correctly.

7. On the IE window, select menu View > Encoding. You should see Gb2312 is selected.

Still not hard to do, right? The key point is to use an editor that compatible with GB2312.

Table of Contents

 About This Book

 Introduction and Installation of PHP

 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

 Archived Tutorials

 References

 Full Version in PDF/EPUB