设为首页收藏本站关注微信<<< 抵制 IE6 人人有责 >>>
搜索
热搜: 活动 交友 discuz
查看: 1668|回复: 0
打印 上一主题 下一主题

[WEB前端] ASP将汉字转换成URL编码函数

[复制链接]
跳转到指定楼层
楼主
发表于 2016-4-14 07:16:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
URL编码就是在URL之间传递的数据,如果直接在URL里加汉字,有的浏览器可以识别,有的浏览器不可以识别,举个简单的例子,在QQ对话框里输入
http://www.kevin-ying.com/tag.php?name=%D7%B7%BC%D3
发送给对话,这个连接是一个整体,而如果是汉字
http://www.kevin-ying.com/tag.php?name=追加
QQ聊天对话框里=号后面的就被忽略了,所以将汉字转换成URL编码是非常必要的
[AppleScript] 纯文本查看 复制代码
<%
Function UrlEncoding(DataStr)
Dim StrReturn,Si,ThisChr,InnerCode,Hight8,Low8
StrReturn = ""
For Si = 1 To Len(DataStr)
ThisChr = Mid(DataStr,Si,1)
If Abs(Asc(ThisChr)) < &HFF Then
StrReturn = StrReturn & ThisChr
Else
InnerCode = Asc(ThisChr)
If InnerCode < 0 Then
InnerCode = InnerCode + &H10000
End If
Hight8 = (InnerCode And &HFF00)\ &HFF
Low8 = InnerCode And &HFF
StrReturn = StrReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
UrlEncoding = StrReturn
End Function
response.Write UrlEncoding("你好")
再告诉你们一个秘密,ASP自带的有这么一个方法server.URLEncode("你好"),效果一样。
%>



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享淘帖
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

QQ|手机版|Archiver|源于生活(个人生活娱乐工作的笔记)css3,html5,学习笔记    

GMT+8, 2024-4-29 20:27 , Processed in 0.078000 second(s), 23 queries .

Powered by Mr.Kevin-ying

© 2004-2015

快速回复 返回顶部 返回列表