php简单读取.vcf格式文件的方法示例

yipeiwu_com5年前PHP代码库

本文实例讲述了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程序设计有所帮助。

相关文章

linux下为php添加iconv模块的方法

./configure --with-mysql=/backup/mysql --with-freetype-dir --with-jpeg-dir --with-png-dir --w...

php上传文件中文文件名乱码的解决方法

可能会有不少朋友碰到一些问题就是上传文件时如果是英文倒好原文名不会有问题,如果是中文可能就会出现乱码了,今天我来给大家总结一下导致乱码php上传文件中文文件名乱码的原因与解决办法吧。 这...

php生成高清缩略图实例详解

本文实例讲述了php生成高清缩略图的方法。分享给大家供大家参考,具体如下: 在使用php的函数生成缩略图的使用,缩略图很多情况下都会失真,这个时候需要有一些对应的解决方法。 1.用ima...

php懒人函数 自动添加数据

复制代码 代码如下: /* *@自动添加数据函数 *@$table 表名 *@$arr 字段库 array("title",array("content",int)) *@ array(...

php的memcached客户端memcached

memcache的官方主页:http://pecl.php.net/package/memcachememcached的官方主页:http://pecl.php.net/package/...