//Export 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 = "Property name, whether a return visit has been made";
$str = iconv(' utf-8','gb2312',$str); //Chinese transcoding
if ($data){
foreach ($data as $d){
$name = iconv('utf-8','gb2312' ,$d['house_name']); //Chinese transcoding
$vis = $d['is_visited']=='y'?"Revisited":"No return visit";
$vis = iconv('utf -8','gb2312',$vis);
$str.= $name.",".$vis."n";
}
}
$filename = $date['start']."-" .$date['end'].$city_cn.'Return calls and visits.csv'; //Set the file name
export_csv($filename,$str); //Export
The above introduces PHP export to CSV, including php and csv content. I hope it will be helpful to friends who are interested in PHP tutorials.