Internet Connection, Inc. Web and Email Hosting
  • Hosting & Email
  • Domain Names
  • Support
  • Design
  • |
  • Login
Affordable Web Hosting with Excellent Customer Support internet connection free month hosting

Perl URL Encode and 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;
Internet Connection IncADDRESS  600 Dover Rd. Ste 204PHONE (410) 820-5678FAX (410) 770-9564
About internet connection inc.Policies© Copyright , internet connection inc.
Internet Connection Live Chat