噢,谢谢啊 2011/3/25 Jeova Sanctus Unus <[email protected]>: > 你需要的uri escape > $ perl -le 'use URI::Escape; print uri_escape("abc中cba")' > abc%E4%B8%ADcba > > 在 2011年3月25日 下午12:17,Robin Lee <[email protected]> 写道: >> 比如输入 "abc中cba",就输出"abc%E4%B8%ADcba"。 >> 主要用于改写URL。 >> 也即是,如果字符是在ASCII范围,则直接输出,否则就按其UTF8编码的16进制输出。 >> 我现在这样来实现: >> >> #!/usr/bin/perl >> use warnings; >> use utf8; >> use Encode; >> >> $s = "abc中cba"; >> >> for (split('',$s)){ >> if (ord($_) < 128){ >> print; >> }else{ >> printf('%%%X',ord($_)) for (split('', encode('UTF-8', $_))); >> } >> } >> print "\n"; >> >> >> 似乎很笨拙,大家想到什么更好的办法? >> >> -- >> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 >> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 >> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。 >> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 >> >> > > -- > 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 > 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。 > 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 > >
-- 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
