這篇文章主要介紹了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讀取 .vcf 格式檔案的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!