绵阳动力网站建设

php读取VCF格式文件以及产生乱码的解决方法和代码

时间:2017-09-04

今天绵阳动力网站建设公司为大家介绍关于php读取VCF格式文件以及产生乱码的解决方法和代码。

1、PHP读取VCF文件:

/**
* 读取.vcf格式文件
* @param $filename
*/
function readCvf($filename){
 $file = fopen($filename,"r");
 while(! feof($file))
 {
   $line=fgets($file);
   $encoding = mb_detect_encoding($line, array('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII'));
   $content = iconv($encoding, "utf-8", $line);
   $arr = explode(":",$content) ;
   if($arr[0]=="NOTE;ENCODING=QUOTED-PRINTABLE"){
   $temp= quoted_printable_decode($arr[1]);
   $encoding = mb_detect_encoding($temp, array('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII'));
   $arr[1] = iconv($encoding, "utf-8", $temp);
   }
   if(count($arr)==2){
    $userInfo[$arr[0]] = $arr[1] ;
   }
 }
 fclose($file);
 return $userInfo;
}

2、产生乱码后的解决办法:

$encoding = mb_detect_encoding($line, array('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII'));
$content = iconv($encoding, "utf-8", $line);

Copyright © 绵阳动力网站建设 www.kf51.cn All Rights Reserved 蜀ICP备08100083号

客服微信
客服微信
0816-6339181
客服微信
my_dongli