php導出excel亂碼

Code:
  1. header("Content-type: application/vnd.ms-excel;");  
  2. header("Content-Disposition:filename=test.xls");  
  3.   
  4. $datas = array(  
  5.         array('id'=>2,'email'=>'[email protected]','name'=>'aa'),  
  6.         array('id'=>4,'email'=>'[email protected]','name'=>'的決定咖啡店'),  
  7.         array('id'=>5,'email'=>'[email protected]','name'=>'CC'),  
  8.         array('id'=>7,'email'=>'[email protected]','name'=>'打開附件的客服金額看風景'),  
  9.         array('id'=>9,'email'=>'[email protected]','name'=>'ss')          
  10.         );  
  11. $table = "<table border='1'>";  
  12. $table .= "<tr>";  
  13. $table .= "<td>id</td><td>email</td><td>name</td>";  
  14. $table .= "</tr>";  
  15. foreach($datas as $key=>$value)  
  16. {  
  17. $table .= "<tr>";  
  18. $table .= "<td>".$value["id"]."</td>";  
  19. $table .= "<td>".$value["email"]."</td>";  
  20. $table .= "<td>".iconv("UTF-8""gb2312",$value["name"])."</td>";  
  21. $table .= "</tr>";  
  22.   
  23. }  
  24. $table .= "</table>";  
  25. echo $table;  

設置charset也解決不了問題header("Content-type: application/vnd.ms-excel;charset=utf-8");

中文部分用iconv函數轉換一下編碼
瀏覽器默認編碼是gb2312

發佈了47 篇原創文章 · 獲贊 10 · 訪問量 37萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章