Re: checking multiple URL parameters
| From: | Andrew Kreps | Date: | Thu, 16 Sep 2004 20:31:08 +0000 |
| Subject: | Re: checking multiple URL parameters | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196912@lists.php.net to get a copy of this message | ||
On Thu, 16 Sep 2004 12:47:26 -0700 (PDT), Chris Shiflett
<shiflett@php.net> wrote:
>
> This makes absolutely no sense to me. What do you mean by submitted? How
> would a PHP script be executed at all if the browser never sends a
> request?
>
PHP can be run from the command line, in which case the GET and POST
arrays wouldn't exist. I use this functionality so that I can take
advantage of Pear's DataObjects when I need to do a flat file data
load. Also, imagine if you had a database of URL's that you wanted to
dissect for it's component information?
That being said, I'm not aware of a PHP function that performs this
operation for you. I remember writing a similar one in Perl many
years ago, that was something like:
(sorry for the pseudocode, I figure completely wrong is better than
almost right)
array = regexp_split (/[=&]/, uri) // where uri is everything after the ?
for (i = 0; i < count(array); i += 2) {
url_var[array[i]] = array[i+1] // You may want to do a urldecode here
}
I believe php lets you name vars by adding an additional $ before the
name, such as:
$varname = "thing";
$$varname = "data";
echo $thing // Produces 'data'
This may be a good starting point.