Solved

urlencode/decode function (unescape)

Posted on 1998-10-01
3
3,484 Views
Last Modified: 2012-06-22
I have urlencoded data (in a database). Retrieving the data is no problem. I wonder if there is an easy way to decode the data. I can write my own function (that is no problem) but it seems likely to me that perl has an inbuilt function for this (which does the same as unescape in javascript).

How do I easily urldecode in perl.

I have found:

use URI::Escape;
and then I can use the function "uri_unescape()", but it does not convert "+" to space. (javascript unescape does that too).
0
Comment
Question by:sybe
  • 2
3 Comments
 
LVL 28

Author Comment

by:sybe
ID: 1205056
Edited text of question
0
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1205057
I'm not sure why the + should be converted to a ' '.  It's not
mentioned in RFC 1630.  However, should you want to do this manually,
you should do it _before_ passing it to uri::uri_unescape i.e.

$data =~ s/([^\\])\+/$1 /g;
$data = uri_unescape($data);

0
 
LVL 28

Author Comment

by:sybe
ID: 1205058
It works (but so did the thing I wrote).
The encoding from " " to "+" was done by ASP/VBScript. What I was really looking for was one function to do it all, but that probably is not present in perl.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question