代码拉取完成,页面将自动刷新
<?php
function fopen_utf8($filename){
$encoding='';
$handle = fopen($filename, 'r');
$bom = fread($handle, 2); //读取文件
// fclose($handle);
rewind($handle); //rewind() 函数将文件指针的位置倒回文件的开头。
// print_r($bom);die();
if($bom === chr(0xff).chr(0xfe) || $bom === chr(0xfe).chr(0xff)){
// UTF16 Byte Order Mark present
$encoding = 'UTF-16';
} else {
$file_sample = fread($handle, 1000) + 'e'; //read first 1000 bytes
// + e is a workaround for mb_string bug
rewind($handle);
$encoding = mb_detect_encoding($file_sample , 'UTF-8, UTF-7, ASCII, EUC-JP,SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP');
}
if ($encoding){
stream_filter_append($handle, 'convert.iconv.'.$encoding.'/UTF-8');
}
// print_r($handle);die();
return ($handle);
}
$file='goods.csv';
if (($handle = fopen_utf8($file)) === FALSE) return;
while (($cols = fgetcsv($handle, 1000, "\t")) !== FALSE) {
echo $cols[0];
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。