国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

ASP讀取Request.QueryString編碼的函數代碼

2024-05-04 11:08:13
字體:
來源:轉載
供稿:網友
ASP讀取Request.QueryString編碼的函數代碼,學習asp的朋友可以參考下。
 
 
 
1. 支持參數純漢字 ?a=深山老熊 
2. 支持參數gb2312 Urlencode編碼: ?a=%C9%EE%C9%BD%C0%CF%D0%DC 
3. 支持參數UTF-8 Urlencode編碼: ?a=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A 
復制代碼代碼如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<% 
Option Explicit 
Const YXCMS_CHARSET = "UTF-8" 
Const YXCMS_CODEPAGE = 65001 
Response.CharSet = "UTF-8" 
Session.CodePage = 65001 
'測試URL 
'?n1=深山老熊&n2=%C9%EE%C9%BD%C0%CF%D0%DC&n3=%E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A 
'深山老熊 
'GBK : %C9%EE%C9%BD%C0%CF%D0%DC 
'UTF-8 : %E6%B7%B1%E5%B1%B1%E8%80%81%E7%86%8A 
Dim URI,key 
Set URI = new Cls_URI 
'輸出所有參數測試 
For Each key In URI.QueryString 
Response.Write "<span style='color:red'>" & key & " : </span>" & URI.Get(key) & "<hr/>" 
Next 
'取單個值 
'URI.Get("名稱") 
'-------------------------------------------- 
'ASP UTF-8編碼下通吃 GBK UTF-8編碼 
'作者: 深山老熊 QQ:81090 
'-------------------------------------------- 
Class Cls_URI 
Private o_item,o_regx 
Private url_query 
Private Sub Class_Initialize 
Set o_item = CreateObject("Scripting.Dictionary") 
o_item.CompareMode = 1 
Set o_regx = New Regexp 
o_regx.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])+$" 
Session.CodePage = 936 
url_query = Request.ServerVariables("QUERY_STRING") 
Session.CodePage = 65001 
'根據QUERY_STRING字符串,生成模擬QueryString值 
Dim i,a,b,c,n,v 
a = Split(url_query,"&") : c = UBound(a) 
For i = 0 To c 
b = Split(a(i),"=",2) 
n = Trim(b(0) & "") 
If UBound(b) < 1 Then 
v = "" 
Else 
v = b(1) 
If InStr(v,"%") > 0 Then v = URLDecode(v) 
End If 
If n <> "" Then 
o_item(n) = v 
End If 
Next 
Set o_regx = Nothing 
End Sub 
Private Sub Class_Terminate 
Set o_item = Nothing 
End Sub 
'模擬 Request.QueryString 
Public Function QueryString() 
Set QueryString = o_item 
End Function 
'模擬 Request.QueryString(n) 
Public Function [GET](n) 
If o_item.Exists(n) Then 
[GET] = o_item.Item(n) 
Else 
[GET] = "" 
End If 
End Function 
'編碼格式化 
Private Function URLDecode(ByVal s) 
Dim sm,cs,r,o_regex 
If Trim(s & "") = "" Then 
URLDecode = s : Exit Function 
End If 
s = unescape(s) 
If o_regx.Test(s) Then 
cs = "UTF-8" 
Else 
cs = "GBK" 
End If 
Set sm = CreateObject("Adodb.Stream") 
With sm 
.Type = 2 
.Mode = 3 
.Open 
.CharSet = "ISO-8859-1" 
.WriteText s 
.Position = 0 
.CharSet = cs 
URLDecode = .ReadText(-1) 
.Close 
End With 
Set sm = Nothing 
End Function 
End Class 
%> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 合阳县| 忻城县| 昂仁县| 施甸县| 华亭县| 沿河| 大埔县| 扎囊县| 霍林郭勒市| 定陶县| 镇沅| 酒泉市| 贡嘎县| 京山县| 通榆县| 灵寿县| 景洪市| 徐闻县| 平罗县| 天台县| 高陵县| 太湖县| 西林县| 承德县| 甘孜| 简阳市| 绥江县| 韶山市| 万载县| 莱州市| 五原县| 开鲁县| 资中县| 含山县| 青海省| 德令哈市| 宽城| 扎赉特旗| 调兵山市| 金门县| 大港区|