1

「mbstring.script_encoding」構成の使用法は何ですか? mbstring.internal_encoding とは違いますか?

http://php.net/manual/en/mbstring.configuration.php

4

1 に答える 1

1

zend.script_encodingです。例を示しましょう。

CP1251 で書かれたスクリプトがあります。

// script encoded as ANSI. var_dump() says false
var_dump(mb_check_encoding('Кириллица', 'UTF-8'));

$input = $_GET['internalInput'];
var_dump(mb_check_encoding($input, 'UTF-8'));

私の INIes には、すでに構成があります。

mbstring.encoding_translation = On
mbstring.internal_encoding = UTF-8

スクリプト テスト

bool(false) 
bool(true)

はキリル$input文字列%D0%F3%F1%F1%EA%E8%E9です。


次に、スクリプト エンコーディングの構成を変更しましょう。(php.iniまたは別のINIes。システム構成によって異なります)で、次のような行を見つけることができます

; If enabled, scripts may be written in encodings that are incompatible with
; the scanner.  CP936, Big5, CP949 and Shift_JIS are the examples of such
; encodings.  To use this feature, mbstring extension must be enabled.
; Default: Off
zend.multibyte = On

; Allows to set the default encoding for the scripts.  This value will be used
; unless "declare(encoding=...)" directive appears at the top of the script.
; Only affects if zend.multibyte is set.
; Default: ""
zend.script_encoding = CP1251

デフォルトでは、これらの行はすべてコメント化されています。ここでは に設定multibyteOn、スクリプト エンコーディングをに設定しCP1251ます。もう一度テストを行います。

スクリプト テスト

bool(true) 
bool(true)

だから...簡単にUTF-8に移行しました:)

于 2012-11-20T10:39:32.373 に答える