php如何判断文件编码格式的
比如a.txt文档,我要判断他是gbk格式的还是utf-8格式,如何判断,如何使utf-8格式,我就让它继续下面的操作,如果不是utf-8格式的,我就提示文件编码格式不正...
比如a.txt文档,我要判断他是gbk格式的还是utf-8格式,如何判断,如何使utf-8格式,我就让它继续下面的操作,如果不是utf-8格式的,我就提示文件编码格式不正确。希望看清楚问题再解答,谢谢!
展开
展开全部
<?php
$str="白";
/***
也可以从文件读取内容
$filename = "a.txt";
$handle = fopen($filename, "r");
$str = fread($handle, filesize ($filename));
fclose($handle);
*/
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8','GB2312',"GBK",'BIG5'));
if($encode=="UTF-8"){
echo "is:UTF-8";
}else{
echo "not:UTF-8";
}
?>
$str="白";
/***
也可以从文件读取内容
$filename = "a.txt";
$handle = fopen($filename, "r");
$str = fread($handle, filesize ($filename));
fclose($handle);
*/
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8','GB2312',"GBK",'BIG5'));
if($encode=="UTF-8"){
echo "is:UTF-8";
}else{
echo "not:UTF-8";
}
?>
追问
我要判断文件,不是字符串
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询