查询出数据库信息后,需要导出到Excel表,片段如下:
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=www.lizu2010.com_".date("Y-m-d").".xls");
header("Pragma: no-cache");
header("Expires: 0");
//导出xls 开始
$tag1 = iconv("UTF-8", "GB2312",'No.');
$tag2 = iconv("UTF-8", "GB2312",'网址');
$tag3 = iconv("UTF-8", "GB2312",'统计结果');
$tag4 = iconv("UTF-8", "GB2312",'关键字');
echo "$tag1\t$tag2\t$tag3\t$tag4\n";
//$key_name = array_keys($arr);
$i = 1;
foreach($arr as $val){
$No = $i;
$url = $val['url'];
$rs = $val['val'];
$keyword = iconv("UTF-8", "GB2312",$val['keyword']);
echo "$No\t$url\t$rs\t$keyword\n";;
$i++;
}
来源:https://www.cnblogs.com/yubinli/p/3655989.html