TIP: url encoding a url in perl

Discussion of Perl, PHP, JavaScript, Python, C, or any other programming languages

Moderators: top25web, Optimizers

TIP: url encoding a url in perl

Postby chovy on Wed Aug 27, 2003 1:54 pm

Here's a simple way to url encode a url in perl using the URI::URL module available from cpan.org.

Create a new $url object, passing it the unencoded url.
Then retrieve the encoded url with the $url->as_string(); method.


Code: Select all
use URI::URL;
my $unencoded_url = 'http://www.this.com/script?a=1 this that&b=2';
my $url = URI::URL->new($unencoded_url);

print "encoded: " . $url->as_string . "\n";

User avatar
chovy
Site Admin
 
Posts: 2521
Joined: Wed Jan 29, 2003 12:01 pm
Location: SF Bay Area

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron