多字节字符串 函数
在线手册:中文  英文

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 是一个 array 或者逗号分隔的字符编码列表。 参见支持的编码

如果省略了 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-16UTF-32UCS2UCS4,编码检测总是会失败。

Example #1 无效检测顺序的例子

; 总是检测为 ISO-8859-1
detect_order = ISO-8859-1, UTF-8

; 总是检测为 UTF-8,由于 ASCII/UTF-7 的值对  UTF-8 是有效的
detect_order = UTF-8, ASCII, UTF-7

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #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());
?>

参见


多字节字符串 函数
在线手册:中文  英文

用户评论:

ben at sixg dot com (2004-04-20 20:31:34)

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().)

易百教程