是的,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"; }