= 4.0.6, PHP 5, PHP 7, PHP 8)mb_detect_encoding — 檢測字符的編碼說明mb_detect_encoding(string $str, mixed $encoding_list = mb_detect_">

mb_detect_encoding

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_detect_encoding檢測字符的編碼

說明

mb_detect_encoding(string $str, mixed $encoding_list = mb_detect_order(), bool $strict = false): string

檢測字符串 str 的編碼。

參數(shù)

str

待檢查的字符串。

encoding_list

encoding_list 是一個(gè)字符編碼列表。 編碼順序可以由數(shù)組或者逗號(hào)分隔的列表字符串指定。

如果省略了 encoding_list 將會(huì)使用 detect_order。

strict

strict 指定了是否嚴(yán)格地檢測編碼。 默認(rèn)是 false

返回值

檢測到的字符編碼,或者無法檢測指定字符串的編碼時(shí)返回 false

范例

示例 #1 mb_detect_encoding() 例子

<?php
/* 使用當(dāng)前的 detect_order 來檢測字符編碼 */
echo mb_detect_encoding($str);

/* "auto" 將根據(jù) mbstring.language 來擴(kuò)展 */
echo mb_detect_encoding($str"auto");

/* 通過逗號(hào)分隔的列表來指定編碼列表 encoding_list */
echo mb_detect_encoding($str"JIS, eucjp-win, sjis-win");

/* 使用數(shù)組來指定編碼列表 encoding_list  */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
echo 
mb_detect_encoding($str$ary);
?>

參見