最近有项目需要将txt文档通过openoffice转为PDF,然后在通过swftools将PDF转为swf,在linux系统下的字符编码方式为utf-8,所以需将不是UTF-8的文本文档转换为UTF-8
/**
* PHP判断文本文档字符编码
*
* @param
* @arrange 网: www.512Pic.com
**/
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");
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528628.html