1NetMedia_Blog

<< JS中encodeURI,escape,encodeURI...  类别: ASP/.NET 手机端界面自动适应屏幕大小 >>
asp中server.urlencode及URLDecode编码及反编码
[ 日期: 2015-01-07 10:30:31 PM | 作者: admin | 来源: 本站整理 | 人气:1504 | 晴天 | 心情: +2 ] 字号: 【
急速栏目链接:
标签:server.urlencode  |  URLDecode  |  编码  |  反编码  |  
''ASP编码及反编码
response.Write(URLDecode(server.urlencode("好人啊!")))


Function URLDecode(strIn)
''server.urlencode转码函数
  URLDecode = ""
  Dim sl: sl = 1
  Dim tl: tl = 1
  Dim key: key = "%"
  Dim kl: kl = Len(key)
  sl = InStr(sl, strIn, key, 1)
  Do While sl>0
  If (tl=1 And sl<>1) Or tl<sl Then
  URLDecode = URLDecode & Mid(strIn, tl, sl-tl)
  End If
  Dim hh, hi, hl
  Dim a
  select Case UCase(Mid(strIn, sl+kl, 1))
  Case "U":'Unicode URLEncode
  a = Mid(strIn, sl+kl+1, 4)
  URLDecode = URLDecode & ChrW("&H" & a)
  sl = sl + 6
  Case "E":'UTF-8 URLEncode
  hh = Mid(strIn, sl+kl, 2)
  a = Int("&H" & hh)'ascii码
  If Abs(a)<128 Then
  sl = sl + 3
  URLDecode = URLDecode & Chr(a)
  Else
  hi = Mid(strIn, sl+3+kl, 2)
  hl = Mid(strIn, sl+6+kl, 2)
  a = ("&H" & hh And &H0F) * 2 ^12 Or ("&H" & hi And &H3F) * 2 ^ 6 Or ("&H" & hl And &H3F)
  If a<0 Then a = a + 65536
  URLDecode = URLDecode & ChrW(a)
  sl = sl + 9
  End If
  Case Else:'Asc URLEncode
  hh = Mid(strIn, sl+kl, 2)'高位
  a = Int("&H" & hh)'ascii码
  If Abs(a)<128 Then
  sl = sl + 3
  Else
  hi = Mid(strIn, sl+3+kl, 2)'低位
  a = Int("&H" & hh & hi)'非ascii码
  sl = sl + 6
  End If
  URLDecode = URLDecode & Chr(a)
  End select
  tl = sl
  sl = InStr(sl, strIn, key, 1)
  Loop
  URLDecode = URLDecode & Mid(strIn, tl)
End function


附JS编码及反编码:
<script>
//JS编码及反编码
document.write("JS编码及反编码<br />"+decodeURI(encodeURI("好人啊!")));
</script>


相关文章:JS中encodeURI,escape,encodeURIComponent编码区别
   
Rss Comment  

没有相关评论

发表评论
请先注册,才能发表评论!
- 注册 -