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; }

经常遇到乱码问题:解决方法两步:

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

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php文件操作总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》及《php字符串(string)用法总结

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/45cde9283076fed01219604c93a0c018.html