7

考虑:

use URI::Escape;
print uri_unescape("%C3%B3");

输出:×

使用此http://meyerweb.com/eric/tools/dencoder/解码

输出:ó

这是预期的。

我应该使用什么 Perl 库来获得正确的输出?

4

3 回答 3

12

如果您知道字节序列是UTF-8,那么使用Encode::decode

use Encode;
use URI::Escape;

my $in = "%C3%B3";
my $text = Encode::decode('utf8', uri_unescape($in));

print length($text);    # Should print 1
于 2012-10-31T18:06:16.637 回答
0

该代码Encode::decode('utf8', uri_unescape($in))对我不起作用,但以下代码运行良好。

sub smartdecode {
    use URI::Escape qw( uri_unescape );
    use utf8;
    my $x = my $y = uri_unescape($_[0]);
    return $x if utf8::decode($x);
    return $y;
}

此代码来自http://lwp.interglacial.com/ch05_02.htm

于 2014-01-04T17:58:59.923 回答
0
于 2021-11-28T21:09:06.947 回答