home  CODE LIBRARY  : Perl URL Encode and Decode 
Web and Email Hosting
More Information about our Web and Email Hosting Solution. Linux Web HostingWindows

Perl URL Encode & Decode String

Here's an excellent way to encode strings that are going to be placed in a URL:

$str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;

$str can now be passed in the query string safely, for example:

<a ref="page_given_string.php?str=$str">LINK</a>

Likely, "page_given_string.php" will want to decode $str back into something useful:

$str =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;

Email and Web Hosting by Internet Connection 2004-2007 ©
Contact IC Support via AIM!  Our SN is ICSupportDesk