RE: [PHP] Passing variables to the script
| From: | Christoph Starkmann | Date: | Wed, 08 May 2002 11:36:32 +0000 |
| Subject: | RE: [PHP] Passing variables to the script | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-96571@lists.php.net to get a copy of this message | ||
Hi!
> Well. I need a function which parses string in format
> "var1=val1&....." and
> creates varibles from it.
> Is there such function?
I'm not sure if there already exists such a function;
In fact you can access these vars if they were attached to the
URL via $HTTP_GET_VARS["var1"] and so forth.
But it would not be too hard to implement one using explode and
variable variables:
$array = explode("&", $string);
$vars = array();
foreach($array as $pair)
{
$var = array();
$var = explode("=", $pair);
$$var[0] = $var[1];
}
Now you can access the values through the var names from the string;
If you put this into a function, though, you'll have to store the
name-value-pairs in a hash that you can return to your main script.
HTH,
Kiko