<?php
function setCsv(){
$outPut_Result = fopen('php://output', 'w') or die("can't open php://output");
$title = '文件标题';
header("Content-Type: application/csv");
header("Content-Disposition: attachment; filename= $title.csv");
/* CSV编码UTF-8, 但是Excel以ANSI编码打开乱码 */
fwrite( $outPut_Result, chr(0xEF).chr(0xBB).chr(0xBF) );
fputcsv($outPut_Result, Array(''));
fputcsv($outPut_Result, Array('时间', '平台订单号', '微信支付订单号', '金额', '币种', '订单状态'));
/* 这里应该循环才对 教程只做演示 */
fputcsv($outPut_Result, Array('02-07', '80000000001', '4250000000000001', '100', 'RMB', 'SUCCESS'));
fputcsv($outPut_Result, Array('02-07', '80000000002', '4250000000000002', '200', 'RMB', 'REFUND'));
fclose($outPut_Result) or die("can't close php://output");
}
setCsv();
?>
image.png
网友评论