運(yùn)行時(shí)配置

這些函數(shù)的行為受 php.ini 中的設(shè)置影響。

mbstring 配置選項(xiàng)
名字 默認(rèn) 可修改范圍 更新日志
mbstring.language "neutral" PHP_INI_ALL PHP_INI_PERDIR 位于 PHP <= 5.2.6
mbstring.detect_order NULL PHP_INI_ALL  
mbstring.http_input "pass" PHP_INI_ALL  
mbstring.http_output "pass" PHP_INI_ALL  
mbstring.internal_encoding NULL PHP_INI_ALL  
mbstring.script_encoding NULL PHP_INI_ALL 在 PHP 5.4.0. 中移除, 使用 zend.script_encoding 代替。
mbstring.substitute_character NULL PHP_INI_ALL  
mbstring.func_overload "0" PHP_INI_SYSTEM PHP <= 5.2.6 是 PHP_INI_PERDIR。 Deprecated as of PHP 7.2.0; removed as of PHP 8.0.0.
mbstring.encoding_translation "0" PHP_INI_PERDIR  
mbstring.http_output_conv_mimetypes "^(text/|application/xhtml\+xml)" PHP_INI_ALL Available as of PHP 5.3.0.
mbstring.strict_detection "0" PHP_INI_ALL 自 PHP 5.1.2 起有效。
有關(guān) PHP_INI_* 樣式的更多詳情與定義,見 配置可被設(shè)定范圍。

這是配置指令的簡短說明。

mbstring.language string

mbstring 使用了國家默認(rèn)語言設(shè)置(NLS)。 注意,該選項(xiàng)自動地定義了 mbstring.internal_encodingmbstring.internal_encoding,在 php.ini 里應(yīng)當(dāng)放置在 mbstring.language 之后。

mbstring.encoding_translation bool

為傳入的 HTTP 查詢啟用透明字符編碼過濾器,將檢測和轉(zhuǎn)換輸入的編碼為內(nèi)部字符編碼(internal character encoding)。

mbstring.internal_encoding string
警告

本特性已自 PHP 5.6.0 起廢棄。強(qiáng)烈建議不要使用本特性。

定義內(nèi)部字符的默認(rèn)編碼。

PHP 5.6 及更新版的用戶應(yīng)該將此選項(xiàng)留空,并設(shè)置 default_charset 作為代替。

mbstring.http_input string
警告

本特性已自 PHP 5.6.0 起廢棄。強(qiáng)烈建議不要使用本特性。

定義 HTTP 輸入字符的默認(rèn)編碼。

PHP 5.6 及更新版的用戶應(yīng)該將此選項(xiàng)留空,并設(shè)置 default_charset 作為代替。

mbstring.http_output string
警告

本特性已自 PHP 5.6.0 起廢棄。強(qiáng)烈建議不要使用本特性。

定義 HTTP 輸出字符的默認(rèn)編碼。

PHP 5.6 及更新版的用戶應(yīng)該將此選項(xiàng)留空,并設(shè)置 default_charset 作為代替。

mbstring.detect_order string

定義字符編碼的默認(rèn)檢測順序。參見 mb_detect_order()。

mbstring.substitute_character string

為無效編碼的字符定義替代字符。 參見 mb_substitute_character() ,查看支持的值。

mbstring.func_overload string
警告

本特性自 PHP 7.2.0 起廢棄,并且自 PHP 8.0.0 起被移除。 強(qiáng)烈建議不要使用本特性。

用 mbstring 對應(yīng)的函數(shù)覆蓋單字節(jié)版本的函數(shù)集。更多信息參見函數(shù)的覆蓋

該設(shè)置僅能通過 php.ini 文件來修改。

mbstring.http_output_conv_mimetypes string

mbstring.strict_detection bool

使用嚴(yán)格的編碼檢測。

根據(jù) ? HTML4.01 規(guī)范,允許 Web 瀏覽器以頁面不同的字符編碼來提交表單。 參見用 mb_http_input() 來檢測瀏覽器使用的字符編碼。

盡管流行的瀏覽器能夠根據(jù)給出的 HTML 文檔合理猜測正確的編碼,但如果能通過 header() 函數(shù)在 HTTP 的 Content-Type 頭內(nèi)或 ini 的 default_charset 里設(shè)置適當(dāng)?shù)?charset 參數(shù)則會更佳。

示例 #1 php.ini 設(shè)置例子

; 設(shè)置默認(rèn)語言
mbstring.language        = Neutral; 設(shè)置默認(rèn)語言 Neutral(UTF-8) (默認(rèn)的值)
mbstring.language        = English; 設(shè)置默認(rèn)語言為 English 
mbstring.language        = Japanese; 設(shè)置默認(rèn)語言為 Japanese

;; 設(shè)置內(nèi)部的默認(rèn)編碼
;; 注意:請確保這個(gè)編碼能被 PHP 所處理
mbstring.internal_encoding    = UTF-8  ; 設(shè)置內(nèi)部的默認(rèn)編碼為 UTF-8

;; 啟用 HTTP 輸入編碼的轉(zhuǎn)換
mbstring.encoding_translation = On

;; 設(shè)置 HTTP 輸入的默認(rèn)編碼
;; 注意:腳本不能修改 http_input 的設(shè)置
mbstring.http_input           = pass    ; 不轉(zhuǎn)換
mbstring.http_input           = auto    ; 設(shè)置 HTTP 輸入為 auto
                                ; "auto" 會根據(jù) mbstring.language 自動擴(kuò)展
mbstring.http_input           = SJIS    ; 設(shè)置 HTTP 輸入編碼為 SJIS
mbstring.http_input           = UTF-8,SJIS,EUC-JP ; 指定順序

;; 設(shè)置 HTTP 輸出的默認(rèn)編碼
mbstring.http_output          = pass    ; 不轉(zhuǎn)換
mbstring.http_output          = UTF-8   ; 設(shè)置 HTTP 輸出編碼為 UTF-8

;; 設(shè)置字符編碼的默認(rèn)檢測順序
mbstring.detect_order         = auto    ; Set detect order to auto
mbstring.detect_order         = ASCII,JIS,UTF-8,SJIS,EUC-JP ; Specify order

;; 設(shè)置默認(rèn)的替代字符
mbstring.substitute_character = 12307   ; 指定 Unicode 值
mbstring.substitute_character = none    ; 不打印字符
mbstring.substitute_character = long    ; Long 的例子: U+3000,JIS+7E7E

示例 #2 php.iniEUC-JP 用戶的設(shè)置

;; 禁用輸出緩沖
output_buffering      = Off

;; 設(shè)置 HTTP header 字符編碼
default_charset       = EUC-JP    

;; 設(shè)置默認(rèn)語言為 Japanese
mbstring.language = Japanese

;; 啟用 HTTP 輸入編碼的轉(zhuǎn)換
mbstring.encoding_translation = On

;; 啟用 HTTP 輸入轉(zhuǎn)換的編碼為 auto
mbstring.http_input   = auto 

;; 轉(zhuǎn)換 HTTP 輸出的編碼為 EUC-JP
mbstring.http_output  = EUC-JP    

;; 設(shè)置內(nèi)部編碼為 EUC-JP
mbstring.internal_encoding = EUC-JP    

;; 不要打印無效的字符
mbstring.substitute_character = none   

示例 #3 php.iniSJIS 用戶的設(shè)置

;; 啟用輸出緩沖
output_buffering     = On

;; 設(shè)置 mb_output_handler 來啟用輸出編碼的轉(zhuǎn)換
output_handler       = mb_output_handler

;; 設(shè)置 HTTP header 的字符編碼
default_charset      = Shift_JIS

;; 設(shè)置默認(rèn)語言為 Japanese
mbstring.language = Japanese

;; 設(shè)置 http 輸入轉(zhuǎn)換的編碼為 auto
mbstring.http_input  = auto 

;; 轉(zhuǎn)換成 SJIS
mbstring.http_output = SJIS    

;; 設(shè)置內(nèi)部變量為 EUC-JP
mbstring.internal_encoding = EUC-JP    

;; 不要打印無效的字符
mbstring.substitute_character = none