URL编码转换回正常的编码asp版
作者:admin 日期:2008-05-10
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
VB实现URL编码与解码
作者:admin 日期:2008-05-10
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
ASP中Utf-8和Gb2312乱码问题的终结
作者:admin 日期:2008-05-10
先说一下基本的东西:
<%@ 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%>
其他编码的类推。
广告位