例如:
我們在百度中搜索 服務器之家,則網址后面的參數就是
http://www.baidu.com/s?cl=3&wd=%BD%C5%B1%BE%D6%AE%BC%D2
如果我們想將%BD%C5%B1%BE%D6%AE%BC%D2還原為中文,使用下面的函數即可。
<%
response.write urldecode("http://www.baidu.com/s?cl=3&wd=%BD%C5%B1%BE%D6%AE%BC%D2")
'================================================
'函數名:URLDecode
'作 用:URL解碼
'================================================
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(192,224,240,248,252,254)
urlcode = Replace(urlcode,"+"," ")
pass = 0
utf8 = -1
length = Len(urlcode) : start = InStr(urlcode,"%") : final = InStrRev(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 > 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 For
End If
Next
If blength > -1 Then
For position = 0 To blength
b1 = URLDecode_Hex(Mid(urlcode,i + position * 3 + 2,2))
If b1 < 128 Or b1 > 191 Then butf8 = 0 : Exit For
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 For
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 For
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
%>
ASP URL反編碼函數代碼
2019-09-04 10:21ASP之家 ASP教程
URL反編碼函數,簡單易懂。 主要是原來的中文進行了url編碼,具體使用的時候需要還原成中文,就需要這樣的函數。
延伸 · 閱讀
- 2022-03-07URL @PathVariable 變量的匹配原理分析
- 2022-03-02詳解Python實現URL監測與即時推送
- 2022-02-22一文帶你理解URI 和 URL 有什么區別?
- 2022-02-22java 遠程文件url如何轉為輸入流
- 2022-02-22Python Django獲取URL中的數據詳解
- 2022-02-18URL如何優化?網站url鏈接如何做有利于網站優化
精彩推薦
- ASP教程
ASP.NET 數據源
數據源 一個 data sourse 控件與數據綁定的控件相互作用,并隱藏了復雜的數據的聯編過程。這些是提供數據給 data bound 控件的工具,并且支持如插入,刪除...
- ASP教程
asp之基于adodb.stream的文件操作類
asp之基于adodb.stream的文件操作類...
- ASP教程
JScript中遍歷Request表單參數集合的方法
這篇文章主要介紹了JScript中遍歷Request表單參數集合的方法,本文以遍歷Request.QueryString集合為例給出了實現代碼,需要的朋友可以參考下...
- ASP教程
ASP常用函數:getpy()
ASP常用函數:getpy()...
- ASP教程
asp Access數據備份,還原,壓縮類代碼
asp Access數據備份,還原,壓縮類實現代碼,大家可以參考下。...
- ASP教程
asp 標記字符串中指定字符變色不區分大小寫
今天遇到這種問題,單純的使用replace函數不行,他會改變原有的字符串的大小寫,在網上找到相關的代碼,自己備份下...
- ASP教程
asp+javascript實現404頁的處理轉換
asp+javascript實現404頁的處理轉換...
- ASP教程
asp 采集實戰代碼
最近實在是太流行采集了,本人是不喜歡采集的,但對采集的原理我卻很有興趣進行研究,拿到了網上采集常用函數,對其進行了一番研究,并實戰,結果...