实例
<?php $ret = [ ['a'=>'a1','b'=>'b1','c'=>'c1'], ['a'=>'a2','b'=>'b2','c'=>'c2'], ['a'=>'a3','b'=>'b3','c'=>'c3'] ]; $fileName = 'abc.csv'; header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=" . $fileName); header("Cache-Control: max-age=0"); $file = fopen("php://output", 'a'); $head = ["列A", "列B", "列C"]; fputcsv($file, $head); foreach ($ret as $row) { fputcsv($file, $row); } fclose($file); die;
运行实例 »
点击 "运行实例" 按钮查看在线实例