首页 > 代码库 > php 导出csv

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);

php 导出csv