php导出excel文档

while($data_array=mysql_fetch_array($result)){
	$data[$i]=$data_array;
	$i++;
}

$title=array("game_name","des","url","add_time");
$keys=array("game_name","des","url","add_time");

exportToExcel($data,'aa.xls',$title,$keys);

function exportToExcel($data,$filename,$title,$keys){		//$keys為data中要導出的數據列
	header('Content-type: text/cvs');
	header("Content-Disposition: attachment; filename=\"$filename\"");
	$top = '數據導出時間:'.date('Y-m-d H:i:s');
	$table	= '';
	$table .= '';
	foreach($title as $value){
		$table .= '';						//列標題
	}
	$table .= '';
	$i =1;
	foreach($data as $value){
		$table .= '';						//序號
		foreach($keys as $key){									//數據內容
			$table .= '';
		}
		$table .= '';
		$i++;
	}
	$table .= '
'.$value.'
'.$i.''.$value[$key].'
'; $top = iconv('utf-8','gbk',$top); $table = iconv('utf-8','gbk',$table); echo $top; echo $table; exit; }