Shell中[如何将中文URL编码]

sh/bash/dash/ksh/zsh等Shell脚本
回复
lifelse
帖子: 78
注册时间: 2008-01-13 20:06

Shell中[如何将中文URL编码]

#1

帖子 lifelse » 2008-11-29 19:10

如题 Shell中[如何将中文URL编码]

类似于

代码: 全选

%5B%E7%94%B5%E5%BD%B1%E5%A4%A9%E5%A0%82
头像
c\nc
帖子: 231
注册时间: 2007-12-25 12:51

Re: Shell中[如何将中文URL编码]

#2

帖子 c\nc » 2008-12-01 18:47

echo -n 汉字 | od -xAn

字节序问题就自己搞吧 :em04
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: Shell中[如何将中文URL编码]

#3

帖子 xhy » 2008-12-01 19:28

php: urlencode
python: urllib.quote
目前负债150多万
lifelse
帖子: 78
注册时间: 2008-01-13 20:06

Re: Shell中[如何将中文URL编码]

#4

帖子 lifelse » 2008-12-01 20:57

呵呵。谢谢各位啊!
明天试试看!
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

Re: Shell中[如何将中文URL编码]

#5

帖子 xiooli » 2008-12-01 21:10

1, urlencode
echo -n "汉字语句" | od -t x1 -A n -w1000|tr " " "%"
2, urldecode
perl -p -e 's/%(..)/pack("c", hex($1))/eg'
lifelse
帖子: 78
注册时间: 2008-01-13 20:06

Re: Shell中[如何将中文URL编码]

#6

帖子 lifelse » 2008-12-03 10:49

xiooli 的答案最简单了。谢谢。
当然其他两文的回复也是正确的经过验证!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: Shell中[如何将中文URL编码]

#7

帖子 eexpress » 2008-12-03 10:59

perl的。我早发过的。处理字符,当然是perl了。
● 鸣学
回复