ASP的URLEncode转发和解码
- by Hector
在网页中,有时候会传送一些中文参数,往往我们需要用URLEncode来进行转码
1、中文转URLEncode
此时有系统自带的函数Server.URLEncode("这里为需要转码的字符串")
2、中文解码
此时系统没有解码函数,可参考如下函数
<% ‘Server.URLEncode(string)的解密函数 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 %>