最新消息:

php 导出csv

PHP bijizhidao 52浏览 0评论

/**

* @param $data=array(“title”=array(中文说明),”list”=array(数据))

* @param $file_name

* @return bool

*/

function down_excel_data($data,$file_name)

{

ob_start();

$fp = fopen(“php://output”, “w”) or die(“Can’t Open php://output”);

fwrite($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));

if(!empty($data[‘title’]))

fputcsv($fp, $data[‘title’]);

if(!empty($data[‘list’])) {

foreach ($data[“list”] as $key => $value)

fputcsv($fp, $value);

}

fclose($fp);

$file = ob_get_contents();

ob_end_clean();

//文件下载header头

header(“Content-type: application/octet-stream”);

header(‘Cache-Control:must-revalidate,post-check=0,pre-check=0’);

header(‘Expires:0’);

header(‘Pragma:public’);

header(“Content-Disposition: attachment; filename=”.$file_name.date(“Ymd”).”.csv”);

echo $file;

}

转载请注明:PHP学习 » php 导出csv

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址