[点晴永久免费OA]ASP中传递中文参数的Server.URLEncode函数转换以及逆转函数URLDecode
|
admin
2019年9月21日 11:36
本文热度 4060
|
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
ASP中的用法:
Response.Write URLDecode("%D1%A7%B6%F8%CA%B1%CF%B0%D6%AE")
输出的结果是:学而时习之
相关教程:
ASP中只有UrlEncode,没有Urldecode问题的解决方法?[
822]
http://17977.oa22.cn
该文章在 2024/11/18 8:57:59 编辑过