当前位置: 技术问答>linux和unix
请问如何把google关键字utf-8转成汉字?
来源: 互联网 发布时间:2015-10-14
本文导语: 请列出代码小程序,谢谢 | $perl --version This is perl, v5.8.6 built for i386-linux-thread-multi $echo $LANG en_US.UTF-8 $cat urlstr2urf8str.pl sub urlstr2utf8str{ $_ = shift @_; $_ =~ s:%%:x00:...
请列出代码小程序,谢谢
|
$perl --version
This is perl, v5.8.6 built for i386-linux-thread-multi
$echo $LANG
en_US.UTF-8
$cat urlstr2urf8str.pl
sub urlstr2utf8str{
$_ = shift @_;
$_ =~ s:%%:x00:g;
$_ =~ s:%([^%]{2}):pack("C",hex("$1")):eg;
$_ =~ s:x00:%:g;
return $_;
}
while(){
print urlstr2utf8str($_);
print "-------------------------------------------------";n
}
$perl urlstr2urf8str.pl
linux+%40%23%40%24O%28%23%40Y%24+%E6%8E%A2%E7%B4%A2+%E5%8F%91%E7%8E%B0
linux+@#@$O(#@Y$+探索+发现
-------------------------------------------------
perl+%E4%B8%AD%E6%96%87
perl+中文
-------------------------------------------------
-http://www.google.com/search?hl=en&lr=&newwindow=1&rls=org.mozilla%3Aen-US%3Aofficial&q=%E9%98%BF%E5%8F%B6%E5%93%AD%E4%BA%86%E3%80%82%E6%88%91%E5%8D%B4%E5%93%AD%E4%B8%8D%E5%87%BA%E6%9D%A5%EF%BC%8C%E5%93%AD%E4%B9%9F%E6%B2%A1%E7%94%A8%E4%BA%86%EF%BC%8C%E6%97%A9%E8%AF%A5%E6%83%B3%E5%88%B0%E4%BC%9A%E8%BF%99%E6%A0%B7%EF%BC%8C%E6%88%91%E4%BB%AC%E5%A4%AA%E5%A4%A9%E7%9C%9F%E4%BA%86%E3%80%82&btnG=Search
-http://www.google.com/search?hl=en&lr=&newwindow=1&rls=org.mozilla:en-US:official&q=阿叶哭了。我却哭不出来,哭也没用了,早该想到会这样,我们太天真了。&btnG=Search
-------------------------------------------------
如果你的locale不是utf8的,那再参考一下iconv函数。
This is perl, v5.8.6 built for i386-linux-thread-multi
$echo $LANG
en_US.UTF-8
$cat urlstr2urf8str.pl
sub urlstr2utf8str{
$_ = shift @_;
$_ =~ s:%%:x00:g;
$_ =~ s:%([^%]{2}):pack("C",hex("$1")):eg;
$_ =~ s:x00:%:g;
return $_;
}
while(){
print urlstr2utf8str($_);
print "-------------------------------------------------";n
}
$perl urlstr2urf8str.pl
linux+%40%23%40%24O%28%23%40Y%24+%E6%8E%A2%E7%B4%A2+%E5%8F%91%E7%8E%B0
linux+@#@$O(#@Y$+探索+发现
-------------------------------------------------
perl+%E4%B8%AD%E6%96%87
perl+中文
-------------------------------------------------
-http://www.google.com/search?hl=en&lr=&newwindow=1&rls=org.mozilla%3Aen-US%3Aofficial&q=%E9%98%BF%E5%8F%B6%E5%93%AD%E4%BA%86%E3%80%82%E6%88%91%E5%8D%B4%E5%93%AD%E4%B8%8D%E5%87%BA%E6%9D%A5%EF%BC%8C%E5%93%AD%E4%B9%9F%E6%B2%A1%E7%94%A8%E4%BA%86%EF%BC%8C%E6%97%A9%E8%AF%A5%E6%83%B3%E5%88%B0%E4%BC%9A%E8%BF%99%E6%A0%B7%EF%BC%8C%E6%88%91%E4%BB%AC%E5%A4%AA%E5%A4%A9%E7%9C%9F%E4%BA%86%E3%80%82&btnG=Search
-http://www.google.com/search?hl=en&lr=&newwindow=1&rls=org.mozilla:en-US:official&q=阿叶哭了。我却哭不出来,哭也没用了,早该想到会这样,我们太天真了。&btnG=Search
-------------------------------------------------
如果你的locale不是utf8的,那再参考一下iconv函数。