欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php判断文本文档字符编码

程序员文章站 2022-06-06 21:48:05
...
跳至
function chkCode($string){
 $code = array('UTF-8','GBK','GB18030','GB2312');
 foreach($code as $c){
  if( $string === iconv('UTF-8', $c, iconv($c, 'UTF-8', $string))){
   return $c;
  }
 }
 return "no";
}

$file1 = 'test1.txt';
$str1 = file_get_contents($file1);
echo chkCode("$str1");