As a very generic answer,
$url =~ s/%20/ /g;
On the other hand, try URI::Escape:
$normal = uri_unescape($escaped);
It unescapes anything URI-escaped. You can also reliably escape strings with uri_escape(). | [reply] [d/l] [select] |
Or, in a more common way:
$string =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
But I prefer using uri_escape or param from CGI...
Best regards,
perl -e "$_=*F=>y~\*martinF~stronat~=>s~<A HREF="/index.pl?node=%5E%5Cw&lastnode_id=1072">^\w</A>~~g=>chop,print" | [reply] [d/l] [select] |
Just one more...
(I also prefer URI::Escape)
sub escape
{
my $toencode = shift;
return undef unless defined($toencode);
$toencode=~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
return $toencode;
}
Hopes
$_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s,
$_^=q,$\^-]!,,print
| [reply] [d/l] [select] |
Straight From the URI::Escape docs:
uri_unescape($string,...)
Returns a string with all %XX sequences replaced with the actual byte
(octet).
This does the same as:
$string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
but does not modify the string in-place as this RE would. Using the
uri_unescape() function instead of the RE might make the code look
cleaner and is a few characters less to type.
In a simple benchmark test I made I got something like 40% slowdown by
calling the function (instead of the inline RE above) if a few chars
where unescaped and something like 700% slowdown if none where. If
you are going to unescape a lot of times it might be a good idea to
inline the RE.
If the uri_unescape() function is passed multiple strings, then each
one is unescaped returned.
------------------------------------
based on Version 3.19 of URI::Escape | [reply] [d/l] |
Why not using pack 'H'?
Something like:
s/%([[:xdigit:]]{2})/pack 'H',$1/eg;
| [reply] [d/l] |
| [reply] |
Becoz i need to get back the parameter past from the uri to make a search command base on the keyword. eg. www.perl.com/name=calvin%20boy. Anyway thank for all the help, i'm very appreciate all the help from u all. it really solve my problem.
| [reply] |
Okay, I guess I'll make the required mention
of using taint. And why do I bring taint up
here? Well all of these implementations
are susceptible to
poison null.
Even if you're doing some data-validation
without taint chances are you'd miss that.
Also note that + is sometimes used to encode
spaces as well.
--
perl -pe "s/\b;([st])/'\1/mg"
| [reply] |