mb_detect_encoding
Detect character encoding
Function name: mb_detect_encoding()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8
Function description: mb_detect_encoding() function is used to detect character encoding of a string.
Usage: string mb_detect_encoding ( string $str [, mixed $encoding_list = mb_detect_order() [, bool $strict = FALSE ]] )
parameter:
Return value: If a matching encoding is found, the encoding name is returned, otherwise FALSE is returned.
Example 1:
$str = "Hello, world!"; $encoding = mb_detect_encoding($str); echo "编码为:" . $encoding;
Output: Encoding as: ASCII
Example 2:
$str = "你好,世界!"; $encoding = mb_detect_encoding($str, "UTF-8,GB2312"); echo "编码为:" . $encoding;
Output: Encoding as: UTF-8
Example 3:
$str = "こんにちは、世界!"; $encoding = mb_detect_encoding($str, "SJIS,EUC-JP,UTF-8"); echo "编码为:" . $encoding;
Output: Encoding as: UTF-8
Notes: