For example:
When we search for the footfall home in Baidu, the parameter behind the URL is
Http://www.baidu.com? CL = 3 & WD = % BD % C5 % B1 % be % D6 % AE % BC % D2
To restore % BD % C5 % B1 % be % D6 % AE % BC % D2 to Chinese, use the following function.
<%
Response. Write urldecode ("http://www.baidu.com/s? CL = 3 & WD = % BD % C5 % B1 % be % D6 % AE % BC % D2 ")
'================================================ ==========
'Function name: urldecode
'Usage: URL Decoding
'================================================ ==========
Function urldecode (byval urlcode)
Dim start, final, length, Char, I, butf8, pass
Dim leftstr, rightstr, finalstr
Dim B0, B1, BX, blength, position, U, utf8
On Error resume next
B0 = array (0, 192,224,240,248,252,254)
Urlcode = Replace (urlcode, "+ ","")
Pass = 0
Utf8 =-1
Length = Len (urlcode): Start = instr (urlcode, "%"): final = faster Rev (urlcode, "% ")
If start = 0 or length <3 then urldecode = urlcode: Exit Function
Leftstr = left (urlcode, start-1): rightstr = right (urlcode, length-2-Final)
For I = start to final
Char = mid (urlcode, I, 1)
If char = "%" then
BX = urldecode_hex (mid (urlcode, I + 1, 2 ))
If BX> 31 and BX <128 then
I = I + 2
Finalstr = finalstr & chrw (BX)
Elseif BX & gt; 127 then
I = I + 2
If utf8 <0 then
Butf8 = 1: blength =-1: b1 = Bx
For position = 4 to 0 step-1
If B1> = b0 (position) and B1 <B0 (Position + 1) then
Blength = position
Exit
End if
Next
If blength>-1 then
For position = 0 to blength
B1 = urldecode_hex (mid (urlcode, I + position * 3 + 2 ))
If B1 <128 or B1> 191 then butf8 = 0: exit
Next
Else
Butf8 = 0
End if
If butf8 = 1 and blength = 0 then butf8 =-2
If butf8>-1 and utf8 =-2 then I = start-1: finalstr = "": Pass = 1
Utf8 = butf8
End if
If pass = 0 then
If utf8 = 1 then
B1 = Bx: u = 0: blength =-1
For position = 4 to 0 step-1
If B1> = b0 (position) and B1 <B0 (Position + 1) then
Blength = position
B1 = (b1 XOR B0 (position) * 64 ^ (Position + 1)
Exit
End if
Next
If blength>-1 then
For position = 0 to blength
BX = urldecode_hex (mid (urlcode, I + 2, 2): I = I + 3
If BX <128 or BX> 191 then u = 0: exit
U = u + (bx and 63) * 64 ^ (blength-position)
Next
If u> 0 then finalstr = finalstr & chrw (b1 + U)
End if
Else
B1 = Bx * & h100: u = 0
BX = urldecode_hex (mid (urlcode, I + 2, 2 ))
If BX> 0 then
U = b1 + bx
I = I + 3
Else
If left (urlcode, 1) = "%" then
U = b1 + ASC (mid (urlcode, I + 3, 1 ))
I = I + 2
Else
U = b1 + ASC (mid (urlcode, I + 1, 1 ))
I = I + 1
End if
End if
Finalstr = finalstr & CHR (u)
End if
Else
Pass = 0
End if
End if
Else
Finalstr = finalstr & char
End if
Next
Urldecode = leftstr & finalstr & rightstr
End Function
Function urldecode_hex (byval H)
On Error resume next
H = "& H" & trim (h): urldecode_hex =-1
If Len (h) <> 4 then exit function
If isnumeric (h) Then urldecode_hex = CINT (h)
End Function
%>