Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: When constructing a URL from script variables, how do I handle spaces properly?

by merlyn (Sage)
on Apr 30, 2000 at 16:01 UTC ( #9737=categorized answer: print w/replies, xml ) Need Help??

Q&A > CGI programming > When constructing a URL from script variables, how do I handle spaces properly? - Answer contributed by merlyn

In fact, if you are trying to construct
<a href="/cgi-bin/editmarine.pl?marine=$marineid">edit marine</a>
You'll run into a lot of problems if $marine is not URI-encoded. So the first step is to trot over to URI::Escape and run it through there. No spaces will be left!

Editor's note:

#Sample Code my $SafeMarine = URI::Escape::uri_escape($marineid); <a href="/cgi-bin/editmarine.pl?marine=$SafeMarine">edit marine</a>

  • Comment on Answer: When constructing a URL from script variables, how do I handle spaces properly?
  • Select or Download Code
Replies are listed 'Best First'.
RE: Answer: When constructing a URL from script variables, how do I handle spaces properly?
by steveAZ98 (Monk) on Jul 25, 2000 at 06:08 UTC
    I've also used the code below to replace spaces with the correct chars.
    $value =~ s/\s/\%20/g;
    And it seems to work good for my purposes.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2020-09-19 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?