文字列の文字エンコーディングを検出しようとしていますが、正しい結果が得られません。
例えば:
$str = "€ ‚ ƒ „ …" ;
$str = mb_convert_encoding($str, 'Windows-1252' ,'HTML-ENTITIES') ;
// Now $str should be a Windows-1252-encoded string.
// Let's detect its encoding:
echo mb_detect_encoding($str,'Windows-1252, ISO-8859-1, UTF-8') ;
そのコードは出力しますISO-8859-1
が、それはWindows-1252
.
これの何が問題なのですか?
編集:
@raina77ow に応じて、例を更新しました。
$str = "€‚ƒ„…" ; // no white-spaces
$str = mb_convert_encoding($str, 'Windows-1252' ,'HTML-ENTITIES') ;
$str = "Hello $str" ; // let's add some ascii characters
echo mb_detect_encoding($str,'Windows-1252, ISO-8859-1, UTF-8') ;
私は再び間違った結果を得ます。