/**
* 读取文档
* @param $path
* @return bool|string
*/
static public function readDocument($path) {
if(!$path) return false;
if (IS_WIN) {
##windows下需要将路径转为GBK
$filePath = iconv("UTF-8", "GBK", $path);
} else {
$filePath = $path;
}
if(file_exists($filePath)) {
$content = file_get_contents($filePath);
if(preg_match('/\.mht$/',$path)){
$content = Utility::mht2html($content);
}
}
else
$content = false;
return $content;
}
//转码为UTF-8
static public function convert2UTF8($content) {
$encodingList = array('UTF-8','GBK','GB2312');
$encoding = mb_detect_encoding($content,$encodingList,true);
if(!$encoding){
$content = iconv('UCS-2', "UTF-8", $content);
if(!$content) return false;
}elseif($encoding != 'UTF-8'){
$content = mb_convert_encoding($content,'UTF-8',$encoding);
}
$content = str_ireplace('gb2312','UTF-8',$content);
return $content;
}
/*
* 读取mht
* @author 宋佳宇
*/
static function mht2html($content) {
$content_header = '/Content-Transfer-Encoding:([\s\S]*?)\n/ims';
preg_match($content_header,$content,$item_results);
if(!$item_results){
return $content;
}
$bianma=trim($item_results[1]);
if($bianma =