in reply to CGI : How to put an "&" into a GET-parameter
... href='script.pl?company=IBM&place=Brussels'. This works nice and fineNo, that was always incorrect. Your browser was letting you get away with mis-encoded data, and now when you actually had text where it makes a difference, you got bit.
Learn to construct your URLs using the proper encoding, and you would not have had to work on the edge cases.
When converting from filenames or data to URLs, URI-encoding should be used. The URI module is good for that.
When including a URL in HTML code, HTML-entity-encoding should be used. The HTML::Entities module is good for that.
If you're not doing both to something that appears in HREF='...', you are putting out broken HTML. Yours was an example of this. Some of the other answers in this thread were good, but some were bad. {sigh} The amount of cargo cult around this problem is amazing.
For gun = Smith & Wesson and drink = Jack Daniels, you'd use code like this:
which correctly prints:use URI; use HTML::Entities; my $u = URI->new("/my/cgi"); $u->query_form("gun" => "Smith & Wesson", drink => "Jack Daniels"); print '<A HREF="', encode_entities("$u"), '">', encode_entities("shoot with Smith & Wesson, and drink Jack Daniels") +, '</A>', "\n";
<A HREF="/my/cgi?gun=Smith+%26+Wesson&drink=Jack+Daniels">shoot wi +th Smith & Wesson, and drink Jack Daniels</A>
Note that the HREF parameter contains examples of both URI and HTML escaping. This is necessary. This is the proper way. If anyone else tells you different, they've not read the RFCs or consulted the experts. (Such as the code that runs this site, which when I checked a moment ago, was still broken for HTML.)
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: •Re: CGI : How to put an "&" into a GET-parameter
by jonadab (Parson) on Jan 28, 2003 at 12:53 UTC | |
|
Re^2: CGI : How to put an "&" into a GET-parameter (PM broke)
by tye (Sage) on Jan 28, 2003 at 17:32 UTC | |
|
Re: •Re: CGI : How to put an "&" into a GET-parameter
by Anonymous Monk on Jan 28, 2003 at 18:59 UTC |