rami.info



URLEncode And URLDecode For Perl

Posted in Code, Perl by Rami on the November 19th, 2005

PHP has builtin functions for urlencode and urldecode functions but for perl I’ve found the following from HERE that does the same thing:

sub URLDecode {
my $theURL = $_[0];
$theURL =~ tr/+/ /;
$theURL =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;
$theURL =~ s/<!–(.|\n)*–>//g;
return $theURL;
}

sub URLEncode {
my $theURL = $_[0];
$theURL =~ s/([\W])/”%” . uc(sprintf(”%2.2x”,ord($1)))/eg;
return $theURL;
}

2 Responses to 'URLEncode And URLDecode For Perl'

Subscribe to comments with RSS or TrackBack to 'URLEncode And URLDecode For Perl'.

  1. Pearls said,

    on February 21st, 2006 at 4:45 pm

    Post anything!

  2. Mark said,

    on March 6th, 2006 at 3:00 pm

    finally a new template. its a lot cooler.

Leave a Reply