导航首页 » 技术教程 » PHP:mb_detect_order()的用法_mbstring函数
PHP:mb_detect_order()的用法_mbstring函数 141 2023-12-11   

mb_detect_order

(PHP 4 >= 4.0.6, PHP 5)

mb_detect_order — 设置/获取 字符编码的检测顺序

说明

mixed mb_detect_order ([ mixed $encoding_list = mb_detect_order() ] )

为编码列表 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-16、UTF-32、 UCS2 和 UCS4,编码检测总是会失败。

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

参见

mb_internal_encoding() - 设置/获取内部字符编码 mb_http_input() - 检测 HTTP 输入字符编码 mb_http_output() - 设置/获取 HTTP 输出字符编码 mb_send_mail() - 发送编码过的邮件


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103