Re: looping the query_string into a $var=$value

From: Date: Mon, 18 Nov 2002 16:49:16 +0000
Subject: Re: looping the query_string into a $var=$value
Groups: php.windows 
Request: Send a blank email to php-windows+get-17013@lists.php.net to get a copy of this message
Interesting... You should check out the 'eval' function: http://www.php.net/manual/en/function.eval.php This can be used to evaluate a string as if its PHP code. Its tricky to use, so you will probably have to do a bit of trial and error, but the required code would look something like this: // you want something like this: $foo = "bar"; $php_to_eval = "\$" . addslashes($key) .
    " = \"" . addslashes($value) "\";";
eval($php_to_eval); You'll need to be VERY careful with $key and $value... make sure it doesn't contain any quotes by using addslashes()... otherwise you just opened up a hacker hole. Read the comments to the documentation at the bottom of the URL above. There's lots of people giving useful tips and tricks... -- Brian 'Bex' Huff bex@stellent.com Phone: 952-903-2023 Fax: 952-829-5424 > > I was wondering how I can loop over the QUERY_STRING server variable to > make all the get variables into a localized variables. I know it has > something to do with setting the variable using a double $$? is that > correct? > > /*localize url vars */ > $urlQuery_string = explode("&", $_SERVER['QUERY_STRING']); > for ($i=0; $i < count($urlQuery_string); $i++) { > $keyvalue = explode("=", $urlQuery_String[$i]); > /* ok now what? */ > } >

« previous php.windows (#17013) next »