考虑:
use URI::Escape;
print uri_unescape("%C3%B3");
输出:×
使用此http://meyerweb.com/eric/tools/dencoder/解码
输出:ó
这是预期的。
我应该使用什么 Perl 库来获得正确的输出?
考虑:
use URI::Escape;
print uri_unescape("%C3%B3");
输出:×
使用此http://meyerweb.com/eric/tools/dencoder/解码
输出:ó
这是预期的。
我应该使用什么 Perl 库来获得正确的输出?
如果您知道字节序列是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
该代码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;
}