ASP中的Server.URLEncode参数转换以及逆转函数
UrlEncode
将字符串以 URL 编码。
返回值: 字符串
函数种类: 编码处理
内容说明
本函数将字符串以 URL 编码。例如空格就会变成加号。
ASP中的用法:
Server.URLEncode("内容")
例如:
<%
Response.Write Server.UrlEncode("学而时习之")
%>
输出的结果是:%D1%A7%B6%F8%CA%B1%CF%B0%D6%AE
程序中接受参数的时候,还需要转换成原来的样子,则需要URLDecode函数,如下:
Function URLDecode(enStr)
dim deStr,strSpecial
dim c,i,v
deStr=""
strSpecial="!""#$%&'()*+,.-_/:;<=>?@[/]^`{|}~%"
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if inStr(strSpecial,chr(v))>0 then
deStr=deStr&chr(v)
i=i+2
else
v=eval("&h"+ Mid(enStr,i+1,2) + Mid(enStr,i+4,2))
deStr=deStr & chr(v)
i=i+5
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
End function
例如:
<%
Response.Write URLDecode("%D1%A7%B6%F8%CA%B1%CF%B0%D6%AE")
%>
输出的结果则是:学而时习之
ASP中的Server.URLEncode参数转换以及逆转函数
最新推荐文章于 2021-06-04 13:41:58 发布