Twitter Subscribe to PHP Blog RSS Feed Email RSS

PHP 扩展:mbstring

添加评论 2008年3月6日
可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明

因为最小化安装的PHP,很多扩展没有启用,在登陆phpMyAdmin时得到一个警告:

The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.

我发现 http://www.php.net/mbstring 上有介绍说:

mbstring provides multibyte specific string functions that help you deal with multibyte encodings in PHP.

Note: If you are connecting to a database with PHP, it is recommended that you use the same character encoding for both the database and the internal encoding for ease of use and better performance.
If you are using PostgreSQL, the character encoding used in the database and the one used in PHP may differ as it supports automatic character set conversion between the backend and the frontend.

也就是说这个扩展是用来使得PHP可以处理多字节编码如汉字、日文、韩文等。因此如果phpMyAdmin连接的数据库等使用多字节编码,就必须使用此扩展。例如下面的字符编码和PHP的配合支持就不太好:

“JIS, SJIS, ISO-2022-JP, BIG-5”

Example#1 php.ini 设置的例子

; Set default language

mbstring.language = Neutral; Set default language to Neutral(UTF-8) (default)
mbstring.language = English; Set default language to English

mbstring.language = Japanese; Set default language to Japanese

;; Set default internal encoding
;; Note: Make sure to use character encoding works with PHP
mbstring.internal_encoding = UTF-8 ; Set internal encoding to UTF-8

;; HTTP input encoding translation is enabled.
mbstring.encoding_translation = On

;; Set default HTTP input character encoding
;; Note: Script cannot change http_input setting.
mbstring.http_input = pass ;No conversion.

mbstring.http_input = auto ;Set HTTP input to auto
; “auto” is expanded to “ASCII,JIS,UTF-8,EUC-JP,SJIS”

mbstring.http_input = SJIS ;Set HTTP2 input to SJIS
mbstring.http_input = UTF-8,SJIS,EUC-JP ;Specify order

;; Set default HTTP output character encoding
mbstring.http_output = pass ;No conversion
mbstring.http_output = UTF-8 ;Set HTTP output encoding to UTF-8

;; Set default character encoding detection order
mbstring.detect_order = auto ; Set detect order to auto
mbstring.detect_order = ASCII,JIS,UTF-8,SJIS,EUC-JP ;Specify order

;; Set default substitute character
mbstring.substitute_character = 12307 ; Specify Unicode value
mbstring.substitute_character = none ; Do not print character
mbstring.substitute_character = long ; Long Example: U+3000,JIS+7E7E

解决办法:
安装PHP扩展:“Multi-Byte String”

评论