- 浏览: 268347 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (263)
- mysql (5)
- boost (6)
- 工具 (10)
- IT生活 (7)
- 多线程 (3)
- Ruby (15)
- php (2)
- MongoDB (39)
- 移动互联网 (2)
- 测试 (8)
- c++ (28)
- 书 (1)
- 网站 (3)
- 网络编程 (14)
- 开源软件 (1)
- 分布式计算 (1)
- 得得得 (1)
- php,wordpress (1)
- error (5)
- 编译 (2)
- 学习 (1)
- 杀毒软件 (1)
- dd (0)
- linux (21)
- 数据库 (1)
- STL (1)
- c++/c (5)
- 软件设计 (1)
- 操作系统 (4)
- 库 (2)
- win32 (1)
- s (0)
- openssl (1)
- perl (2)
- debug (1)
- windows (4)
- python (12)
- windows 防火墙 (1)
- vs (1)
- vim (2)
- vc (1)
- 浏览器插件的危害 (1)
- curl (0)
- 判断手机号码合法性的库 (0)
- 地址备注 (0)
- 安装 File::Slurp (1)
- cenos (2)
- shell (1)
- linunx (1)
- internet (1)
- software (1)
- widows (1)
- linux io (1)
- nginx (2)
- 算法 (2)
- google (1)
- protobuf (2)
- tengine (1)
- tools (1)
- lua (2)
- liunx (1)
- vcard (1)
- lua-iconv (1)
- 网络 (2)
- teat (0)
- ldconfig linux (0)
- awk (0)
- grep (0)
- windws (2)
- linux 命令 (1)
- tcp dump (1)
- vmware (1)
- question2answer (2)
- mongdb (1)
- 正则 (1)
- OCR (2)
- Windows Server (1)
最新评论
方法一:
def URLDecode(str)
str.gsub!(/%[a-fA-F0-9]{2}/) { |x| x = x[1..2].hex.chr }
end
def URLEncode(str)
str.gsub!(/[^\w$&\-+.,\/:;=?@]/) { |x| x = format("%%%x", x[0]) }
end
链接:http://www.2maomao.com/blog/2-ruby-cookies-en-de-code/
方法二:
采用ERB::Util.url_encode()
其中在url_encode 处理如下
def url_encode(s)
s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
end
在正则表达式中:
[^a-zA-Z0-9_\-.]表示匹配非a-z 和A-Z 包括0-9 以及下划线和-中横线 的字符,
$& 全局变量,匹配到的字符串存放在 $& 变量中
uppack 是字符对象中的一个方法:是拆字符到数组的函数,
str.unpack( format ) -> anArray
Decodes str (which may contain binary data) according to the format string,
returning an array of each value extracted. 。。
其中C表示按字符拆。还有参数如下:
Directives for String#unpack
Format Function Returns
A String with trailing nulls and spaces removed. String
a String. String
B Extract bits from each character (msb first). String
b Extract bits from each character (lsb first). String
C Extract a character as an unsigned integer. Fixnum
c Extract a character as an integer. Fixnum
d Treat sizeof(double) characters as a native double. Float
E Treat sizeof(double) characters as a double in little-endian byte order. Float
e Treat sizeof(float) characters as a float in little-endian byte order. Float
f Treat sizeof(float) characters as a native float. Float
G Treat sizeof(double) characters as a double in network byte order. Float
g Treat sizeof(float) characters as a float in network byte order. Float
H Extract hex nibbles from each character (most significant first). String
h Extract hex nibbles from each character (least significant first). String
I Treat sizeof(int) 1 successive characters as an unsigned native integer. Integer
i Treat sizeof(int) 1 successive characters as a signed native integer. Integer
L Treat four1 successive characters as an unsigned native long integer. Integer
l Treat four1 successive characters as a signed native long integer. Integer
M Extract a quoted-printable string. String
m Extract a base64 encoded string. String 能把base64直接解出。
N Treat four characters as an unsigned long in network byte order. Fixnum
n Treat two characters as an unsigned short in network byte order. Fixnum
P Treat sizeof(char *) characters as a pointer, and return len characters from the referenced location. String
p Treat sizeof(char *) characters as a pointer to a null-terminated string. String
S Treat two1 successive characters as an unsigned short in native byte order. Fixnum
s Treat two1 successive characters as a signed short in native byte order. Fixnum
U Extract UTF-8 characters as unsigned integers. Integer
u Extract a UU-encoded string. String
V Treat four characters as an unsigned long in little-endian byte order. Fixnum
v Treat two characters as an unsigned short in little-endian byte order. Fixnum
X Skip backward one character. ---
x Skip forward one character. ---
Z String with trailing nulls removed. String
@ Skip to the offset given by the length argument.
其中参数带个上述格式,还可在格式后跟个数字or*,表示做几次拆解,
我靠,日本人搞的东西咋这么复杂呢,以为是unix啊,@#¥%!@#¥!,慢慢看吧。
自我感觉比c难学。不过他这一步就可以做好多事情,很好很强大啊。
转:http://www.cnitblog.com/kenlistian/archive/2008/03/25/41469.html
def URLDecode(str)
str.gsub!(/%[a-fA-F0-9]{2}/) { |x| x = x[1..2].hex.chr }
end
def URLEncode(str)
str.gsub!(/[^\w$&\-+.,\/:;=?@]/) { |x| x = format("%%%x", x[0]) }
end
链接:http://www.2maomao.com/blog/2-ruby-cookies-en-de-code/
方法二:
采用ERB::Util.url_encode()
其中在url_encode 处理如下
def url_encode(s)
s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
end
在正则表达式中:
[^a-zA-Z0-9_\-.]表示匹配非a-z 和A-Z 包括0-9 以及下划线和-中横线 的字符,
$& 全局变量,匹配到的字符串存放在 $& 变量中
uppack 是字符对象中的一个方法:是拆字符到数组的函数,
str.unpack( format ) -> anArray
Decodes str (which may contain binary data) according to the format string,
returning an array of each value extracted. 。。
其中C表示按字符拆。还有参数如下:
Directives for String#unpack
Format Function Returns
A String with trailing nulls and spaces removed. String
a String. String
B Extract bits from each character (msb first). String
b Extract bits from each character (lsb first). String
C Extract a character as an unsigned integer. Fixnum
c Extract a character as an integer. Fixnum
d Treat sizeof(double) characters as a native double. Float
E Treat sizeof(double) characters as a double in little-endian byte order. Float
e Treat sizeof(float) characters as a float in little-endian byte order. Float
f Treat sizeof(float) characters as a native float. Float
G Treat sizeof(double) characters as a double in network byte order. Float
g Treat sizeof(float) characters as a float in network byte order. Float
H Extract hex nibbles from each character (most significant first). String
h Extract hex nibbles from each character (least significant first). String
I Treat sizeof(int) 1 successive characters as an unsigned native integer. Integer
i Treat sizeof(int) 1 successive characters as a signed native integer. Integer
L Treat four1 successive characters as an unsigned native long integer. Integer
l Treat four1 successive characters as a signed native long integer. Integer
M Extract a quoted-printable string. String
m Extract a base64 encoded string. String 能把base64直接解出。
N Treat four characters as an unsigned long in network byte order. Fixnum
n Treat two characters as an unsigned short in network byte order. Fixnum
P Treat sizeof(char *) characters as a pointer, and return len characters from the referenced location. String
p Treat sizeof(char *) characters as a pointer to a null-terminated string. String
S Treat two1 successive characters as an unsigned short in native byte order. Fixnum
s Treat two1 successive characters as a signed short in native byte order. Fixnum
U Extract UTF-8 characters as unsigned integers. Integer
u Extract a UU-encoded string. String
V Treat four characters as an unsigned long in little-endian byte order. Fixnum
v Treat two characters as an unsigned short in little-endian byte order. Fixnum
X Skip backward one character. ---
x Skip forward one character. ---
Z String with trailing nulls removed. String
@ Skip to the offset given by the length argument.
其中参数带个上述格式,还可在格式后跟个数字or*,表示做几次拆解,
我靠,日本人搞的东西咋这么复杂呢,以为是unix啊,@#¥%!@#¥!,慢慢看吧。
自我感觉比c难学。不过他这一步就可以做好多事情,很好很强大啊。
转:http://www.cnitblog.com/kenlistian/archive/2008/03/25/41469.html
发表评论
-
rubuy http
2013-03-28 16:15 659http://ruby-doc.org/stdlib-2.0/ ... -
[转]ruby正则表达式
2013-01-17 18:31 1124ruby正则表达式 Posted on 02/21/2012 ... -
[转]一步一步学Ruby(九):Ruby正则表达式(上)
2013-01-10 17:24 614记录个链接:http://www.cnblogs.com/cn ... -
【转】ruby 杀系统进程
2012-07-12 10:50 750require 'win32ole' #功能说明: #- ... -
【转】ruby 调用其他函数
2012-06-27 19:53 9061、获取其他程序的运行结果 x= system(" ... -
ruby 下载文件到本地
2012-05-19 16:36 1197require 'open-uri' def dow ... -
ruby 解析 xml
2012-05-17 20:16 17891.xml文件如下: <?xml version=&q ... -
gem
2012-04-12 14:00 0gem list gem install gem instal ... -
gem 安装 找不到 http://gems.rubyforge.org/
2012-04-12 11:45 1211使用Gem install安装starling出错 ERROR ... -
sublime ruby 编辑器
2012-03-02 19:13 732http://v.youku.com/v_show/id_XM ... -
mongodb 的 ruby 支持安装
2012-02-07 14:01 779帮助文档: 1. http://api.mongodb.org ... -
Ruby 读取文件
2011-11-23 17:17 871读写二进制文件 File.open('in.dat' ... -
Ruby 网络编程
2011-11-03 16:38 963Ruby支持很多网络协议,不管是高层的还是底层的。ruby提供 ... -
ruby中数字与数字字符串相加的原理
2011-08-19 15:41 1103转: http://googya.iteye.com/blog ... -
Ruby invalid multibyte char(US-ASCALL)
2011-08-10 14:08 889需正确输出中文的方法: 在运行脚本文件时,加入相关的参数-Ks ...
相关推荐
`urlencode` 是一种编码方法,其目的是将非ASCII字符或者在URL中具有特殊含义的字符转换为可以在URL中安全传输的形式。例如,空格通常被转换为 `%20`,其他如逗号、引号等也需转换。这是因为URL本身只允许包含字母、...
`urlEncode` 是一个过程,它将URL中可能引起问题的字符转换为百分比编码,以确保URL的正确性和可读性。URLs只能包含ASCII字符集中的某些字符,如字母、数字、标点符号和某些保留字符。如果URL中包含非ASCII字符或者...
今天小编就为大家分享一篇Python3中urlencode和urldecode的用法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
自己写的,可能有bug,请大家一块学习 环境为PB12 函数(及参数) 作用 arraysort 对一维数组进行排序 ...urldecode 将指定字符串以进行指定字符集url解码 urlencode 将指定字符串以进行指定字符集url编码 涨价了,哈哈
在深入理解JavaScript实现UrlEncode和UrlDecode函数的过程中,我们需要理解几个关键点:首先,URL编码和解码在Web开发中是一种常见的需求,用于确保URL中的特殊字符被正确传输。其次,JavaScript提供了一些内置的...
本文主要讨论如何在ASP中实现URLEncode和URLDecode这两个功能,以便正确地处理URL中的特殊字符和编码问题。 首先,URL编码(URLEncode)是为了在URL中传递非ASCII字符或特殊字符时避免产生错误。URL中不能包含某些...
这个是 utf-8版本的 js实现 php的 urlencode() 和 urldecode()两个函数的功能。 在传送cookie的时候 在 php端实现 url编码 但要用 js来解码cookie的时候 就出现汉字不能不能识别的问题 这个 js 很好的解决
idea插件toolsMix (记录下班时间、实时中英文翻译、jsonView、urlEncode、urlDecode、timeFormate) 解压toolsMix.zip,toolsMix目录下的zip包为打包好的插件包,可以直接安装
文章还指出,在JavaScript中,decodeURI函数并不能完全替代urldecode函数,因为decodeURI只能解码URL中的百分号编码序列,并不处理加号表示空格的情况,也不处理对特殊字符集以外的编码进行解码的需求。因此,需要...
相反,UrlDecode则是UrlEncode的逆过程,它将URL中编码的字符还原为原始形式。当接收到一个编码过的URL后,UrlDecode会识别并替换所有形如"%xy"的序列,将其转化为对应的ASCII字符。 UrlEncode和UrlDecode在实际...
UrlEncode就是将URL中的特殊字符或非ASCII字符转换为百分号(%)加两位十六进制数的形式,以确保URL在传输过程中不会被误解或损坏。例如,空格会被转换为"%20"。 UrlDecode则是URL编码的逆过程,它将已经编码的URL...
原生的PHP提供了urlencode和urldecode这两个内置函数,用于对URL中的特殊字符进行编码和解码。然而,在某些特定的场景下,我们可能需要自定义这些函数的行为,以满足特定的编码或解码需求。本文将详细介绍如何在PHP...
URLEncode是将URL中的非字母数字字符转换为ASCII码的百分号编码形式,如空格通常会被转换为"%20"。这样做的原因是URL中不能包含某些字符,如空格、引号等,它们需要被转义以防止被误解或破坏URL的结构。而URLDecode...
在实际应用中,`urlEncode`和`urlDecode`常用于构建和解析URL,特别是当URL中包含查询字符串时。例如,如果你要创建一个指向搜索引擎的链接,查询参数可能包含用户输入的数据,这些数据必须先编码再加入到URL中,以...
总体而言,自定义的URLEncode和URLDecode函数在ASP开发中提供了更大的灵活性,允许开发者根据实际情况对数据进行更精细的处理。在处理XML或HTML数据时尤其有用,因为它们可以避免不必要的编码,从而保持数据的完整性...
PHP作为广泛使用的服务器端脚本语言,提供了两个非常重要的函数:urlencode() 和 urldecode(),用于处理URL中的非ASCII字符以及避免URL中的特殊字符带来的问题。 ### urlencode() 函数 urlencode() 函数的主要作用...