Home >Backend Development >PHP Tutorial >How to read .vcf format files in php
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);
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!