Re: Re: a general perl like pares of the query string...
| From: | Michael Kimsal | Date: | Sat, 08 Sep 2001 17:30:12 +0000 |
| Subject: | Re: Re: a general perl like pares of the query string... | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66539@lists.php.net to get a copy of this message | ||
Aaron, CC Zona wrote before that:
If track_vars is on (always true if version >= 4.0.3), then the global vars $HTTP_GET_VARS['bob'] and $HTTP_GET_VARS['phil'] are already set.
And if register_globals is on, then the global vars $bob and $phil are also already set.
--------------------------------------
Taking from your original post -
file.php?bob=manager&phil=employ
If you create a file.php in your server, and hit it with file.php?bob=manager,
you should just be able to say
<? echo $bob; ?>
and you'll get "manager" printed out for you. Most installations of PHP, by default,
create variables for you from the GET string parameters. There can be a security concern
if you're not careful to validate the data that you get in from those GET strings,
but this 'ease of use' (not having to use that Perl stuff from below, or firing up CGI.pm
every request) is one of the main attractions to PHP for beginning developers.
CC Zona also wrote that you can use the $HTTP_GET_VARS array (which would
be the equivalent to the $fields{} array that is created below. One really
nifty thing about PHP that isn't addressed in your Perl snippet below is arrays -
file.php?name[]=mike&name[]=dave&name[]=keith
would give me an array called $name with 3 elements in it. There's most likely
a Perl module to handle that (does CGI.pm handle that) but it's handled automatically
in PHP.
Aaron Moore wrote:
Well hers teh perl version of the the parser... how do i convert this to php $tmp = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $tmp); foreach $item (@pairs) { ($key, $content) = split(/=/,$item,2); $content =~ tr/+/ /; $content =~ s/%(..)/pack("c",hex($1))/ge; $fields{$key} = $content; }