downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mb_encode_mimeheader> <mb_detect_encoding
[edit] Last updated: Fri, 25 May 2012

view this page in

mb_detect_order

(PHP 4 >= 4.0.6, PHP 5)

mb_detect_order文字エンコーディング検出順序を設定あるいは取得する

説明

mixed mb_detect_order ([ mixed $encoding_list ] )

自動文字エンコーディング検出の順番を encoding_list に設定します。

パラメータ

encoding_list

encoding_list は、 配列またはカンマ区切りの文字エンコーディングのリストです。サポートされる文字エンコーディングを参照ください。

encoding_list が省略された場合は、 現在の文字エンコーディング検出順を配列で返します。

この設定は、mb_detect_encoding() および mb_send_mail() に影響します。

mbstring が現在実装しているのは、 以下のエンコーディングを検出するフィルタです。 以下のエンコーディングにおいて無効なバイトシーケンスがあった場合、 エンコーディング検出は失敗します。

UTF-8, UTF-7, ASCII, EUC-JP,SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP

ISO-8859-*の場合、mbstring は常に ISO-8859-* として検出します。

UTF-16, UTF-32, UCS2, UCS4 の場合、 エンコーディング検出は常に失敗します。

例1 無意味な順番の例

; 常に ISO-8859-1 として検出されます
detect_order = ISO-8859-1, UTF-8

; ASCII/UTF-7 の値は UTF-8 として有効なため、常に UTF-8 として検出されます
detect_order = UTF-8, ASCII, UTF-7

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例2 mb_detect_order() の例

<?php
/* リストで検出順を設定 */
mb_detect_order("eucjp-win,sjis-win,UTF-8");

/* 配列で検出順を設定 */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
mb_detect_order($ary);

/* 現在の検出順を表示 */
echo implode(", "mb_detect_order());
?>

参考

  • mb_internal_encoding() - 内部文字エンコーディングを設定あるいは取得する
  • mb_http_input() - HTTP 入力文字エンコーディングを検出する
  • mb_http_output() - HTTP 出力文字エンコーディングを設定あるいは取得する
  • mb_send_mail() - エンコード変換を行ってメールを送信する



add a note add a note User Contributed Notes mb_detect_order
ben at sixg dot com 20-Apr-2004 08:31
Note that as of mbstring.c version 1.142.2.31, first released as PHP 4.3.4RC3, "auto" has changed meaning.  It used to be configured based on #defines, so it was set at compile time, so for precompiled binary users (esp. Windows users) it has always been the same (Japanese mode).  However, it is now based on the language that mbstring is configured for at runtime.  (setlocale() doesn't affect this though)  Running on English Windows at least, mbstring defaults to a "neutral" mode which results in an "auto" list of "ASCII, UTF-8".  So, the point is, for PHP 4.3.4 or newer, you probably want to either use mb_language("Japanese") followed by mb_detect_order("auto"), or just hardcode your detect order with mb_detect_order("ASCII, JIS, UTF-8, EUC-JP, SJIS").  (Also note that mb_language() alone won't do it, you'll have to set the detect order to "auto" _after_ calling mb_language().)

 
show source | credits | stats | sitemap | contact | advertising | mirror sites