ASP URL反编码函数代码_应用技巧

例如:
我们在百度中搜索 ,则网址后面的参数就是
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
%>

时间: 2024-08-01 21:01:25

ASP URL反编码函数代码_应用技巧的相关文章

ASP URL反编码函数代码

例如: 我们在百度中搜索 脚本之家,则网址后面的参数就是 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") '==============

ASP通用分页样式函数代码_应用技巧

<% '****************************** '函数:MultiPage(Numbers,Perpage,Curpage,Url_Add) '参数:Numbers,总记录数:Perpage,每页记录数:Curpage,当前页:Url_Add,当前页其它参数如?action=list& '作者:阿里西西 '日期:2007/7/15 '描述:ASP通用分页样式函数 '示例:MultiPage(100,10,2,"?action=list&")

捕捉并保存ASP运行错误的函数代码_应用技巧

过程名:catch(str) 使用方法: 复制代码 代码如下: on error resume next '你的代码,如数据库连接 call catch("显示给用户的提示信息") 功能:清除IIS的错误提示信息,自定义错误提示返回给用户,并将出错信息保存到txt文件(当然你也可以稍做修改转向自定义页面等) 代码: 复制代码 代码如下: <% option explicit '例一--------------------------- '必须和on error resume ne

asp base64加解密函数代码_应用技巧

复制代码 代码如下: <% sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS) Function strUnicodeLen(asContents) '计算unicode字符串的Ansi编码的长度 asContents1="a&q

asp.net 网页编码自动识别代码_实用技巧

复制代码 代码如下: using System; using System.Net; using System.Text; using System.Text.RegularExpressions; class Program { // 获取网页的HTML内容,根据网页的charset自动判断Encoding static string GetHtml(string url) { return GetHtml(url, null); } // 获取网页的HTML内容,指定Encoding sta

asp.net textarea换行函数代码_实用技巧

复制代码 代码如下: /// <summary> /// 替换html中的特殊字符 /// </summary> /// <param name="theString">需要进行替换的文本.</param> /// <returns>替换完的文本.</returns> public string HtmlEncode(string theString) { theString=theString.Replace(&

ASP生成UTF-8编码的代码_应用技巧

方法一:createtextfile生成文件方法 function WriteToFile(FileName,FileContent)     set fso=server.createobject("scripting.filesystemobject")     set fp=fso.createtextfile(server.mappath(FileName),,True)     fp.write(FileContent) end function 方法二:ADODB.Stre

ASP.NET自动为URL加上超链接的代码_实用技巧

作为一个程序员,在完成设计后还要根据程序的情况以及用户的反映不断对程序进行改进,这样才能不断地完善自己的作品.笔者在制作完软件商务网的论坛后,发现人们总喜欢在帖子中加上各种有用的URL链接或Email地址.而笔者当初设计时没有考虑到这一点,使得这些URL链接或Email地址只能以文字的形式而并不是以超链接的形式显示,其它浏览帖子的人还必须把这些URL链接拷贝到浏览器中或把Email地址拷贝到Outlook中才能转到相应的链接地址或发送电子邮件到相应的Email地址. 发现这个问题后,笔者即着手进

最详细的ASP.NET微信JS-SDK支付代码_实用技巧

本文实例为大家分享了微信JS SDK支付的具体代码,供大家参考,具体内容如下 模型层实体类: public class JsEntities { /// <summary> /// 公众号id /// </summary> public string appId { get; set; } /// <summary> /// 时间戳 /// </summary> public string timeStamp { get; set; } /// <su