mb_detect_order
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
mb_detect_order — 设置/获取 字符编码的检测顺序
参数
encoding
-
encoding
是一个 array 或者逗号分隔的字符编码列表。 参见支持的编码。如果省略
encoding
或为null
,它将返回当前字符编码检测顺序的数组。该设置会影响 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
,编码检测总是会失败。
更新日志
版本 | 说明 |
---|---|
8.0.0 |
现在 encoding 可以为 null。
|
示例
示例 #1 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());
?>
示例 #2 案例展示了无效的检测顺序
; 总是检测为 ISO-8859-1 detect_order = ISO-8859-1, UTF-8 ; 总是检测为 UTF-8,由于 ASCII/UTF-7 的值对 UTF-8 是有效的 detect_order = UTF-8, ASCII, UTF-7
参见
- mb_internal_encoding() - 设置/获取内部字符编码
- mb_http_input() - 检测 HTTP 输入字符编码
- mb_http_output() - 设置/获取 HTTP 输出字符编码
- mb_send_mail() - 发送编码过的邮件
+添加备注
用户贡献的备注 1 note
Anonymous ¶
1 year ago
Perhaps obvious to most everyone, but the
default filter list was shorter than I expected:
['ASCII','UTF-8'], in that order.
c. 2024, 60% of websites globally declared charset 'UTF-8'
So if you're experimenting with multibyte encodings other than UTF-8, you have to specify your detect_order, choosing from the list of implemented filters.
备份地址:http://www.lvesu.com/blog/php/function.mb-detect-order.php