溫馨提示×

PHP mb_detect_encoding能檢測UTF-8嗎

PHP
小樊
86
2024-07-16 13:33:42
欄目: 編程語言

是的,PHP的mb_detect_encoding函數(shù)可以用來檢測字符串的編碼格式,包括UTF-8編碼。當檢測到UTF-8編碼時,函數(shù)會返回"UTF-8"。示例代碼如下:

$text = "你好,世界!";
$encoding = mb_detect_encoding($text, "UTF-8");

if($encoding == "UTF-8"){
    echo "字符串編碼為UTF-8";
}else{
    echo "字符串編碼不是UTF-8";
}

0