Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

CGI-encoded quote characters

by Anonymous Monk
on Oct 10, 2001 at 21:23 UTC ( #118059=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I pass the URL within query string together and translate the double quote into CGI-encoded quote characters. such as"att+dsl" became within URL, how?

Replies are listed 'Best First'.
Re: CGI-encoded quote characters
by echo (Pilgrim) on Oct 10, 2001 at 21:31 UTC
    Here's one way:

    use URI::Escape; my $url = '' . uri_escape('q="att+dsl +"');
Re: CGI-encoded quote characters
by projekt21 (Friar) on Oct 10, 2001 at 21:37 UTC

    As you may already use CGI; you can do it with (updated, thanks to echo):

    my $escaped_url = $url . CGI::escape($query_string);

    alex pleiner <>
    zeitform Internet Dienste

      Be careful not to escape the whole URL though, you want to leave those slashes intact. Only the query string itself should be escaped.

      If you are already parsing the parameters with CGI it does it automatically.

      I tend to do $cgi->Vars() which returns a hash of all parameters to the script. It returns the parameters of the query string if it is a GET or the form if it is a POST. I wrote a little test script:

      #!/usr/bin/perl use CGI; my $cgi = new CGI; my %form = $cgi->Vars(); print "Content-type:text/html\n\n"; print "<html><body>\n"; foreach my $key(keys %form) { print "$key = $form{$key}<br>\n"; } print "</body></html>\n"; exit;

      I fed it this url:

      It printed "something" something_else. The point is that CGI will handle this automatically.

        If you reread the question, you will see, that Anonymous Monk asked for tips to ENCODE the query string...

        alex pleiner <>
        zeitform Internet Dienste

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://118059]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2022-05-16 09:57 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (62 votes). Check out past polls.