作者lauw (新港解说营)
看板Google_Map
标题[请益] URI乱码问题...
时间Fri Apr 16 11:18:08 2010
※ [本文转录自 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
1F:推 ebliswu:php版4705篇可看看~ 04/16 17:56
2F:→ lauw:感谢大大的回答! 04/17 01:30