ASP read Request.QueryString Coded function code _ Application Tips

Source: Internet
Author: User
Tags urlencode
1. Support parameter pure Chinese characters? A= Mountain Old Bear
2. Support parameter gb2312 UrlEncode code:? A=%C9%EE%C9%BD%C0%CF%D0%DC
3. Support parameter UTF-8 UrlEncode code:? a=%e6%b7%b1%e5%b1%b1%e8%80%81%e7%86%8a
Copy Code code as follows:

<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<%
Option Explicit
Const yxcms_charset = "UTF-8"
Const yxcms_codepage = 65001
Response.Charset = "UTF-8"
Session.CodePage = 65001
' Test URL
'? n1= Mountain Old Bear &n2=%c9%ee%c9%bd%c0%cf%d0%dc&n3=%e6%b7%b1%e5%b1%b1%e8%80%81%e7%86%8a
' The Old Mountains bear
' 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
' Output all parameter tests
For the each key in URI. QueryString
Response.Write "<span style= ' color:red ' >" & Key & ": </span>" & URI. Get (Key) & "Next
' Take a single value
' URI. Get ("name")
'--------------------------------------------
' ASP UTF-8 code under the GBK UTF-8 code
' Author: Old mountain Bear 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
' Generates the simulated querystring value based on the query_string string
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
' Analog request.querystring
Public Function QueryString ()
Set querystring = O_item
End Function
' Analog Request.QueryString (n)
Public Function [Get] (n)
If O_item. Exists (n) Then
[Get] = O_item. Item (N)
Else
[Get] = ""
End If
End Function
' Encoding format
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
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.