1、完美解决 导出乱码问题,<EOT>标签需要顶格写,前面不能任何字符
<?php
//表示输出的类型为excel文件类型
header( "Content-Type: application/vnd.ms-excel; name='excel'" );
//弹框下载文件
header("Content-Disposition:attachment;filename=".date('Y-m-d',time())."报表.xls");
echo <<< EOT
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head><meta http-equiv="Content-type" content="text/html;charset=utf-8" /></head>
<body>
<table border="1" width="80%">
<tr>
<td align="center">编号</td>
<td align="center">用户名</td>
<td align="center">性别</td>
<td align="center">年龄</td>
</tr>
EOT;
$list = array
(
"0" => array('id'=>1,'username'=>'YQJ','sex'=>'男','age'=>24),
"1" => array('id'=>2,'username'=>'fsd','sex'=>'女','age'=>25),
);
foreach($list as $row){
echo <<< EOT
<tr>
<td align="center">{$row["id"]}</td>
<td align="center">{$row["username"]}</td>
<td align="center">{$row["sex"]}</td>
<td align="center">{$row["age"]}</td>
</tr>
EOT;
}
echo <<< EOT
</table>
</body>
</html>
EOT;
?>