//導出csv
function export_csv($filename,$data) {
header("Content-type:text/csv;charset=utf-8");
header("Content-Disposition:attachment;filename=". $filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $data;
}
$data = $component->getFeedBackList($city_en,$date,0,0);
$str = "樓盤名稱,是否已回訪n";
$str -8','gb2312',$str); //中文轉碼
if ($data){
foreach ($data as $d){
$name = iconv('utf-8','gb2312', $d['house_name']); //中文轉碼
$vis = $d['is_visited']=='y'?"已回訪":"未回訪";
$vis = iconv('utf-iconv('utf-icon 8','gb2312',$vis);
$str.= $name.",".$vis."n";
}
}
$filename = $date['start']."-". $date['end'].$city_cn.'來電回訪狀況.csv'; //設定檔名
export_csv($filename,$str); //匯出
以上就介紹了PHP導出CSV,包含了php,csv方面的內容,希望對PHP教學有興趣的朋友有幫助。