Home  >  Article  >  Backend Development  >  How to read .vcf format files in php

How to read .vcf format files in php

墨辰丷
墨辰丷Original
2018-05-18 10:48:051720browse

This article mainly introduces the method of reading .vcf format files in PHP, and analyzes the specific implementation methods and related precautions of PHP custom functions to read VCF format files based on specific examples. Friends in need can refer to the following

The details are as follows:

/**
* 读取.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;
}

We often encounter garbled code problems: two-step solution:

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

Related recommendations:

How to read file names in python to generate a list

How about H5’s FileReader Distribution of reading files

The above is the detailed content of How to read .vcf format files in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn