[专题] 2024-04-28 圈点467
摘要:asp处理编码问题,ASP对URL地址解码,用于utf-8与GB2312转中文字符通用。
asp对 requst编码处理
当A -> 请求AJAX - B -> 写入数据库
A -GB2312
B -GB2312
这里B页面可以用下面的代码,将B值正常的写入数据库
asp处理编码问题
'URL地址解码,用于utf-8与GB2312转中文字符通用
Function DecodeURI(ByVal s)
s = UnEscape(s)
Dim reg, cs
cs = "GBK"
Set reg = New RegExp
reg.Pattern = "^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$"
If reg.Test(s) Then cs = "UTF-8"
Set reg = Nothing
Dim sm
Set sm = CreateObject("ADODB.Stream")
With sm
.Type = 2
.Mode = 3
.Open
.CharSet = "iso-8859-1"
.WriteText s
.Position = 0
.CharSet = cs
DecodeURI = .ReadText(-1)
.Close
End With
Set sm = Nothing
End Function
在接收页可以这样得到正确的中文字符:
username=DecodeURI(server.URLEncode(username))
下面的实际使用中通过:
username=DecodeURI(server.URLEncode(request("username")))
上一篇[专题]
下一篇[专题]asp_cookies的说明和示例