復(fù)制代碼 代碼如下:
<?php
$file = fopen('text.csv','r');
while ($data = fgetcsv($file)) { //每次讀取CSV里面的一行內(nèi)容
//print_r($data); //此為一個(gè)數(shù)組,要獲得每一個(gè)數(shù)據(jù),訪問數(shù)組下標(biāo)即可
$goods_list[] = $data;
}
//print_r($goods_list);
echo $goods_list[0][1];
fclose($file);
?>
CSV的讀取操作
復(fù)制代碼 代碼如下:
<?php
$file = fopen('D:/file/file.csv','r');
while ($data = fgetcsv($file)) { //每次讀取CSV里面的一行內(nèi)容
print_r($data); //此為一個(gè)數(shù)組,要獲得每一個(gè)數(shù)據(jù),訪問數(shù)組下標(biāo)即可
}
fclose($file);
?>
CSV的寫入操作
復(fù)制代碼 代碼如下:
<?php
$fp = fopen('d:/file/file.csv', 'w');
fputcsv($fp,array('aaa','bbb','cccc'));
fputcsv($fp,array('mmm','yyy','haha')); //fputcsv可以用數(shù)組循環(huán)的方式進(jìn)行實(shí)現(xiàn)
fclose($fp);
?>
輸出CSV(下載功能)
新聞熱點(diǎn)
疑難解答