unescape a string that came from a url, back into plain text.
sub unuriescape { # Note from RFC1630: "Sequences which start with a percent sign # but are not followed by two hexadecimal characters are reserved # for future extension" my $str = shift; if (@_ && wantarray) { # not executed for the common case of a single argument my @str = @_; # need to copy return map { s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg } $str, @str; } $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; $str; }

Replies are listed 'Best First'.
Re: Decode a string from a URL
by Anonymous Monk on Mar 04, 2002 at 16:25 UTC
    two comments:

    1) It doesn't look like your code handles translating + to space

    2) You can also use CGI::Util::unescape to decode a single string (and I have a lot of trust that the CGI.pm people did it right :) )