温馨提示×

PHP mb_detect_encoding能检测UTF-8吗

PHP
小樊
88
2024-07-16 13:33:42
栏目: 编程语言

是的,PHP的mb_detect_encoding函数可以用来检测字符串的编码格式,包括UTF-8编码。当检测到UTF-8编码时,函数会返回"UTF-8"。示例代码如下:

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

if($encoding == "UTF-8"){
    echo "字符串编码为UTF-8";
}else{
    echo "字符串编码不是UTF-8";
}

0