作者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
2F:→ pillsn:或是去找 用php解译javascript escape()的方法 12/20 17:41
3F:→ ebliswu:感谢pillsn大大的说明!escape换成decodeURI就ok了! 12/20 19:41
4F:→ ebliswu:前面的php档的内容都不用动到^o^ 12/20 19:43
5F:→ ebliswu:用firefox都可正常使用。用ie资料库文字栏出现空白Orz... 12/20 21:11
6F:推 aitch:请使用SQL语句:SET SESSION collation_connection="utf8_g" 12/21 00:49
7F:→ aitch:续:"utf8_general_ci" 12/21 00:50
8F:→ ebliswu:如果用mysql_query("SET SESSION collation_connection= 12/21 01:53
9F:→ ebliswu:'utf8_general_ci'");会出现文字但ie及firefox都呈现乱码 12/21 01:54