把数据库里面的数据导出来csv
function export_csv($filename, $data, $head = '')
{
$string = $head;
foreach ($data as $key => $value) {
foreach ($value as $k => $val) {
$value[$k] = iconv('utf-8', 'utf-8', $value[$k]);
}
$string .= implode(",", $value) . PHP_EOL; //用英文逗号分开
}
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=" . $filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $string;
}