Created
October 29, 2008 09:10
-
-
Save sids/20661 to your computer and use it in GitHub Desktop.
Perl: URI encoding/decoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; use warnings; | |
use URI::Escape; | |
# http://www.perlhowto.com/encode_and_decode_url_strings | |
my $string = "Hello world!"; | |
my $encode = uri_escape($string); | |
print "Original string: $string\n"; | |
print "URL Encoded string: $encode\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; use warnings; | |
# http://support.internetconnection.net/CODE_LIBRARY/Perl_URL_Encode_and_Decode.shtml | |
# encode: | |
$uri =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; | |
# decode: | |
$uri =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment