php简单读取.vcf格式文件的方法示例
更新时间:2017年09月02日 11:16:43 作者:crowxiao
这篇文章主要介绍了php简单读取.vcf格式文件的方法,结合具体实例形式分析了php自定义函数读取vcf格式文件的具体实现方法与相关注意事项,需要的朋友可以参考下
本文实例讲述了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)用法总结》
希望本文所述对大家PHP程序设计有所帮助。
相关文章
解析PHP的Yii框架中cookie和session功能的相关操作
这篇文章主要介绍了PHP的Yii框架中cookie和session功能的相关操作,需要的朋友可以参考下2016-03-03
PHP正则替换函数preg_replace和preg_replace_callback使用总结
这篇文章主要介绍了PHP正则替换函数preg_replace和preg_replace_callback使用总结,本文是在写一个模板引擎遇到一个特殊需求时总结而来,需要的朋友可以参考下2014-09-09


最新评论