php_mbstring.dll - Multibyte String Extension

This section describes how to configure PHP to load the mbstring extension (php_mbstring.dll) to support multibyte string functions for UTF-8 encoding.

PHP built-in string functions does allow you to use PHP string variables to store Chinese character strings in UTF-8, GB18030, or Bug5 encoding. But if you want manipulate, like trim, split, substring, count, etc., you need treat them as binary strings of encoded bytes, not characters.

If you want to manipulate Chinese character strings as characters, you need load the "mbstring" extension, php_mbstring.dll. This tutorial shows you how to load and configure php_mbstring.dll for UTF-8 encoding.

1. Check the PHP configuration file, \local\php\php.ini. If not exist, make a copy from \local\php\php.ini-dist, or \local\php\php.ini-production:

C:\herong> copy \local\php\php.ini-dist \local\php\php.ini

C:\herong> rem or:
C:\herong> copy \local\php\php.ini-dist \local\php\php.ini-production

2. Open \local\php\php.ini in a text editor, like notepad.

3. Change the setting to allow PHP to load php_mbstring.dll from the \local\php\ext directory:

...
;extension_dir = "./"
extension_dir = "./ext"
...

;extension=mbstring
extension=mbstring
...

Note that PHP 7 has changed the extension naming convention. For example:

PHP 7: 
   extension=mbstring

PHP 5: 
   extension=php_mbstring.dll

3. Change the setting to set default encoding to UTF-8 for all languages:

...
;mbstring.language = Japanese
mbstring.language = Neutral
...

;mbstring.internal_encoding = EUC-JP
mbstring.internal_encoding = UTF-8
...

There are many other mbstring settings in the configuration file. You can leave them as is, because they do not affect the basic multibyte functions. We will review them later in this book.

Last update: 2019.

Table of Contents

 About This Book

 PHP Installation on Windows Systems

 Integrating PHP with Apache Web Server

 charset="*" - Encodings on Chinese Web Pages

 Chinese Characters in PHP String Literals

Multibyte String Functions in UTF-8 Encoding

php_mbstring.dll - Multibyte String Extension

 mb_strlen() - Counting Multibyte Characters

 List of Multibyte String Functions

 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

 Archived Tutorials

 References

 Full Version in PDF/EPUB