php 导出csv

1.下面是一个非常简单的例子,你可以复制下来运行就可以了,代码如下:

header('Content-Type: application/vnd.ms-excel;charset=gbk');
header('Content-Disposition: attachment;filename=test_' . time() . '.csv');
header('Cache-Control: max-age=0');
$list = array
(
"George,John,Thomas,USA",
"James,Adrew,Martin,USA",
);

$file = fopen('php://output', 'a');

foreach ($list as $line)
{
fputcsv($file,explode(',',$line));
}

fclose($file);
posted @ 2017-06-03 15:16  KOBE-Jason  阅读(168)  评论(0编辑  收藏  举报