Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

( #9624=categorized question: print w/ replies, xml ) Need Help??
Contributed by rodry on Apr 28, 2000 at 23:44 UTC
Q&A  > CGI programming


Description:

I have a script that will construct a link to another PERL script and pass it parameters based on a column returned by a query.
There is a problem however. This column that I am passing as a parameter may or may not have spaces in it. More than likely it will have spaces.
So my question is: how do I detect this spaces and replace them with the appropiate ASCII character code.
As an alternative, how do I filter the user input when providing values for this column so that it will eliminate the spaces, if any?
Thanks in advance

Answer: When constructing a URL from script variables, how do I handle spaces properly?
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>

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 scrutinizing the Monastery: (11)
    As of 2014-09-02 09:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (21 votes), past polls