Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Encode and Decode strings from URL. (See related posts)

Encode a string so that it's safe to be passed in a url. Equivalent of urlencode in PHP.
$str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;


Now, the reverse, decode a string from a url. Equivalent of urldecode in PHP.
$str =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;


You need to create an account or log in to post comments to this site.


Related Posts