[請益] PHPExcel 連結亂碼問題

看板PHP作者 (批踢踢小神童)時間15年前 (2010/12/09 02:38), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
最近買了一本Excel + PHP WEB資料庫開發 按照書上教學試作了商品訂購網頁 網頁顯示的部份是正常 但是連結EXCEL檔到網頁中就為亂碼 小弟的網頁架購為UTF-8的 該如何除錯呢? 以下為程式碼 <?php /************************************************* 【A】前期處理 *************************************************/ // 開始session session_start(); // 讀取函式庫 require_once("PHPExcel/IOFactory.php"); // 載入Excel檔案 $obj = PHPExcel_IOFactory::load("temp.xlsx"); // 設定現用工作表 $obj->setActiveSheetIndex(0); $sheet = $obj->getActiveSheet(); /************************************************* 【B】製作商品資料庫 *************************************************/ // 將商品資料放入陣列中 foreach ($sheet->getRowIterator() as $row) { // 越過標題列(1列) if ($row->getRowIndex() == 1) { continue; } // 取得全欄 $cols = $row->getCellIterator(); // 處理各欄 $ar_prod = NULL; foreach ($cols as $col) { // 將A欄(商品ID)當成索引 if (substr($col->getCoordinate(), 0, 1) == "A") { $idx = $col->getValue(); } else { // 將A欄以外(商品名稱與單價)放入陣列 $ar_prod[] = toUTF($col->getValue()); } } // 將一個商品資料放入陣列 $ar_prods[$idx] = $ar_prod; } // 將商品資料的陣列放入session變數中 $_SESSION["prods"] = $ar_prods; // 變更文字編碼用的函數 function toUTF($a) { return mb_convert_encoding($a, "UTF-8" ,"BIG-5"); } /************************************************* 【C】製作訂購用商品清單 *************************************************/ $select = "<table border=\"1\"><tr bgcolor=\"silver\">"; $select .= "<td width=\"200\">商品名稱</td>"; $select .= "<td width=\"100\">單價(日圓)</td>"; $select .= "<td width=\"50\">數量</td></tr>"; foreach ($_SESSION["prods"] as $prod_id=>$prod) { $select .= "<tr>"; $select .= "<td>{$prod[0]}</td>"; $select .= "<td align=\"right\">" . number_format($prod[1]) . "</td>"; $select .= "<td>"; $select .= "<select name=\"prod-{$prod_id}\">"; for ($i = 0; $i <= 10; $i++) { $select .= "<option value='$i'>$i</option>"; } $select .= "</select>"; $select .= "</td>"; $select .= "</tr>"; } $select .= "</table>"; ?> <!--************************************************ 【D】顯示訂購畫面 ************************************************--> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>訂購表單</title> </head> <body> <center> <form method="POST" action="confirm.php"> <p>請選擇訂購商品的數量</p> <?php echo $select; ?> <p>請輸入寄送地址</p> <table border="1"> <tr> <td bgcolor="silver">姓名</td> <td><input type="text" name="name" size="30"></td> </tr> <tr> <td bgcolor="silver">郵遞區號</td> <td><input type="text" name="postcode" size="10"></td> </tr> <tr> <td bgcolor="silver">地址</td> <td><input type="text" name="address" size="54"></td> </tr> <tr> <td bgcolor="silver">聯絡事項</td> <td> <textarea rows="3" cols="30" name="message"></textarea> </td> </tr> <tr> <td align="right" colspan="2"> <input type="submit" name="sub1" value="確認訂購內容"> </td> </tr> </table> </form> </center> </body> </html> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.252.159.243
文章代碼(AID): #1C_z2eGJ (PHP)
文章代碼(AID): #1C_z2eGJ (PHP)