作者ebliswu (□形的世界)
看板PHP
標題Re: [請益] 如何上傳中文字串?
時間Thu Dec 20 14:04:30 2007
※ 引述《yuan0258 (阿元)》之銘言:
: 假設如果你是用url傳值的方式
: 例如:
: upload_1.php
: ==============================================================================
: <?php
: $name = '你說你';
: $address = '想要逃';
: $lat = '我卻';
: $lng = '偏偏';
: $type = '不想讓你逃';
: //urlencode要在傳值之前就先編碼,中文在經過URL傳值必須先經過編碼
: $name=urlencode($name);
: $address=urlencode($address);
: $lat=urlencode($lat);
: $lng=urlencode($lng);
: $type=urlencode($type);
: $url=<<<F
: <a href=upload_2.php?name=$name&address=$address&lat=$lat&lng=$lng&type=$type>
: 測試連結</a>
: F;
: echo $url;
: ?>
: 然後在upload_2.php要新增到資料庫之前必須加上mysql_query("SET NAMES 'UTF8'");
: 這樣才能確保新增到資料庫的資料是透過UTF8編碼的
感謝你的回覆…看來是我的上傳連結出了問題。
上傳的內容如下:(不是屬php的範圍,請見諒…有高手知道的請指點一下…)
function saveData() {
var name = escape(document.getElementById("name").value);
var address = escape(document.getElementById("address").value);
var type = document.getElementById("type").value;
var latlng = marker.getLatLng();
var lat = latlng.lat();
var lng = latlng.lng();
var url = "phpsqlinfo_addrow.php?name=" + name + "&address=" + address
+ "&type=" + type + "&lat=" + lat + "&lng=" + lng;
GDownloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length <= 1) {
marker.closeInfoWindow();
document.getElementById("message").innerHTML = "Data added.";
}
});
}
請問要修改哪裏呢?謝謝!
--
看不見你的笑我怎麼睡得著…
你的呻吟這麼近我卻抱不到…
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.172.156.201
→ pillsn:或是去找 用php解譯javascript escape()的方法 12/20 17:41
→ ebliswu:感謝pillsn大大的說明!escape換成decodeURI就ok了! 12/20 19:41
→ ebliswu:前面的php檔的內容都不用動到^o^ 12/20 19:43
→ ebliswu:用firefox都可正常使用。用ie資料庫文字欄出現空白Orz... 12/20 21:11
推 aitch:請使用SQL語句:SET SESSION collation_connection="utf8_g" 12/21 00:49
→ aitch:續:"utf8_general_ci" 12/21 00:50
→ ebliswu:如果用mysql_query("SET SESSION collation_connection= 12/21 01:53
→ ebliswu:'utf8_general_ci'");會出現文字但ie及firefox都呈現亂碼 12/21 01:54