Perl笔记

Monday, August 07, 2006

把utf8字符输出成url格式

sub url_encode {
# default argument is $_
local $_ = @_ ? shift : $_;
defined or return;

# change unsafe characters (except for space) to encoded value
s/([^\w()'*~!.-])/sprintf '%%%02x', ord($1)/eg;

# change spaces to +
tr/ /+/;

return $_;
}



0 Comments:

Post a Comment

<< Home