Chinese Web Sites Using PHP - v2.23, by Herong Yang
Chinese Character String with Big5 Encoding
This section provides information on handling Chinese character string literals in Big5 encoding.
Chinese character strings should use UTF-8 encoding. But for some reason, if you have to use Big5 encoding for your Chinese character strings, you can use PHP string as binary strings to store Chinese character strings in Big5 encoding. In order to output Chinese characters to Web pages and display them correctly, you need to:
Here is a simple test I did on my local system:
1. Run my Chinese text editor that supports Big5 encoding.
2. Enter the following PHP script file:
<?php #- String-Big5.php #- Copyright (c) 2005 HerongYang.com. All Rights Reserved. # header('Content-Type: text/html; charset=Big5'); $help = '?????????????'; print('<html>'); print('<meta http-equiv="Content-Type"'. ' content="text/html; charset=big5"/>'); print('<body>'); print('<b>Chinese string in Big5 in PHP</b><br/>'); print($help.'<br/>'); print('</body>'); print('</html>'); ?>
You see some question marks (?) in the source code listed above, because this book uses UTF-8 encoding. Big5 encoded characters can not be included here.
Note that I have added the header() function call to set encoding in the HTTP response header to "Big5", because PHP 7 is using "UTF-8" as the default.
3. Save the as String-Big5.php in Big5 encoding. On my Chinese text editor, I had to select "GB text file" as the "Save as type" to ensure my document was saved in Big5 encoding. Like many other Chinese text editors, it supports multiple encodings. If you are not careful, the document could be saved with a wrong encoding.
4. Copy String-Big5.php to \local\apache\htdocs.
5. Now run Internet Explorer (IE) with http://localhost/String-Big5.php. You should see Chinese characters displayed correctly:
This proves that the editor: notepad, the CGI program: PHP CGI, the Web server: Apache, and the Web browser: IE, all worked correctly with Chinese characters in Big5 encoding.
Table of Contents
PHP Installation on Windows Systems
Integrating PHP with Apache Web Server
charset="*" - Encodings on Chinese Web Pages
►Chinese Characters in PHP String Literals
String Data Type, Literals and Functions
Chinese Character String with UTF-8 Encoding
Chinese Character String with GB18030 Encoding Error
Chinese Character String with GB18030 Encoding
►Chinese Character String with Big5 Encoding
UTF-8 Encoding Pages with Big5 Characters
Multibyte String Functions in UTF-8 Encoding
Input Text Data from Web Forms
Input Chinese Text Data from Web Forms
MySQL - Installation on Windows
MySQL - Connecting PHP to Database
MySQL - Character Set and Encoding
MySQL - Sending Non-ASCII Text to MySQL
Retrieving Chinese Text from Database to Web Pages
Input Chinese Text Data to MySQL Database