预览模式: 普通 | 列表

URL编码转换回正常的编码asp版

ASP中把中文和一些符号转换为URL编码直接有一个函数直接转,但是却没有反编码的函数,这样很多人都比较麻烦。在网站找了很长时间才找到了以下的一个函数,效果不错,贴上来提供有需要的朋友分享。

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

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2916

VB实现URL编码与解码

Private Sub Command1_Click()
Text2.Text = URLEncode(Text1.Text)
End Sub


Public Function URLEncode(ByRef strURL As String) As String
Dim I As Long
Dim tempStr As String
For I = 1 To Len(strURL)
If Asc(Mid(strURL, I, 1)) < 0 Then
tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
URLEncode = URLEncode & tempStr
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Then
URLEncode = URLEncode & Mid(strURL, I, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
End If
Next
End Function

Public Function URLDecode(ByRef strURL As String) As String
Dim I As Long

If InStr(strURL, "%") = 0 Then URLDecode = strURL: Exit Function

For I = 1 To Len(strURL)
If Mid(strURL, I, 1) = "%" Then
If Val("&H" & Mid(strURL, I + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
I = I + 5
Else
URLDecode = URLDecode & Chr(Val("&H" & Mid(strURL, I + 1, 2)))
I = I + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, I, 1)
End If
Next
End Function

Private Sub Command2_Click()
Text3.Text = URLDecode(Text2.Text)
End Sub

Private Sub Form_Load()
Text1.Text = "微迈互联"
End Sub  

Tags: vb

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3785

ASP中Utf-8和Gb2312乱码问题的终结

研究好多天了,也试过好多办法了,总结出目前发现最好的方法:
先说一下基本的东西:
<%@ codepage=65001%>UTF-8
<%@ codepage=936%>简体中文
<%@ codepage=950%>繁体中文
<%@ codepage=437 %>美国/加拿大英语
<%@ codepage=932 %>日文
<%@ codepage=949 %>韩文
<%@ codepage=866 %>俄文

codepage指定了IIS按什么编码读取传递过来的串串(表单提交,地址栏传递等)。

出乱码的原因也就是网站要整合的时候模块编码不一样引起的。
就像我的博客一样,整合的时候都会出这个问题,因为BLOG是Utf-8的,
近来很多网友都在为这个问题咨询,我尝试了很多种方法。
最方便的方法如下:
不要转换任何模块网页的编码该utf-8的还是utf-8,该Gb22312的还是Gb2312
在Utf-8模块的包文件(如conn.asp,但是要注意conn.asp必须是在第一行调用)最前面加上
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
在GB2312模块的包文件最前面加上
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Session.CodePage=936%>
其他编码的类推。

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2698

 广告位

↑返回顶部↑