- header("Content-type: application/vnd.ms-excel;");
- header("Content-Disposition:filename=test.xls");
- $datas = array(
- array('id'=>2,'email'=>'[email protected]','name'=>'aa'),
- array('id'=>4,'email'=>'[email protected]','name'=>'的決定咖啡店'),
- array('id'=>5,'email'=>'[email protected]','name'=>'CC'),
- array('id'=>7,'email'=>'[email protected]','name'=>'打開附件的客服金額看風景'),
- array('id'=>9,'email'=>'[email protected]','name'=>'ss')
- );
- $table = "<table border='1'>";
- $table .= "<tr>";
- $table .= "<td>id</td><td>email</td><td>name</td>";
- $table .= "</tr>";
- foreach($datas as $key=>$value)
- {
- $table .= "<tr>";
- $table .= "<td>".$value["id"]."</td>";
- $table .= "<td>".$value["email"]."</td>";
- $table .= "<td>".iconv("UTF-8", "gb2312",$value["name"])."</td>";
- $table .= "</tr>";
- }
- $table .= "</table>";
- echo $table;
設置charset也解決不了問題header("Content-type: application/vnd.ms-excel;charset=utf-8");
中文部分用iconv函數轉換一下編碼
瀏覽器默認編碼是gb2312