看板 GIS 關於我們 聯絡資訊
※ [本文轉錄自 PHP 看板] 作者: lauw (新港解說營) 看板: PHP 標題: [請益] URI亂碼問題... 時間: Fri Apr 16 11:13:41 2010 不知道能不能問一點google map api的東西, 最近想結合Mysql php googlemap,而官方有一個範例, http://code.google.com/intl/zh-TW/apis/maps/articles/phpsqlinfo.html 但是它沒考慮到用get方法傳中文字存到mysql時,造成亂碼。 http://docs.google.com/present/view?id=dd6fgr97_1453g3s68dh 因為其中用到google map api提供的GDownloadUrl(),只提供get,沒有post。 在phpsqlinfo_add.html這個網頁時,會先將使用者輸入的name、address編碼為URI (使用encodeURIComplonent) function saveData() { var name = document.getElementById("name").value; var name = encodeURIComponent(name); var address = document.getElementById("address").value; var address = encodeURIComponent(address); var type = document.getElementById("type").value; var latlng = marker.getPosition(); 然後在另一個phpsqlinfo_addrow.php用get取得每個數的值。 但是在範例就沒有進行decode去把它URI還原成UTF-8。 $name = $_GET['name']; $address = $_GET['address']; $lat = $_GET['lat']; $lng = $_GET['lng']; $type = $_GET['type']; http://docs.google.com/present/view?id=dd6fgr97_1453g3s68dh 然後筆者將上面改成這樣, $name = rawurldecode($_GET['name']; $name = mb_convert_encoding($name, "UTF-8"); $address = rawurlencode($_GET['address']); $address = mb_convert_encoding($address, "UTF-8"); $lat = $_GET['lat']; $lng = $_GET['lng']; $type = $_GET['type']; 不過這樣網頁它就無法將使用者文字存入mysql,卡住。 不知道那裡我想不清楚。 潛水很久了,初次發文,有許多不懂的地方,請多包涵。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.122.218.68 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.122.218.68
ebliswu:php版4705篇可看看~ 04/16 17:56
lauw:感謝大大的回答! 04/17 01:30