Re: Building an array from a URL

From: Date: Wed, 04 Apr 2001 16:25:51 +0000
Subject: Re: Building an array from a URL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47091@lists.php.net to get a copy of this message
I think the function parse_str does exactly what you want. http://www.php.net/manual/en/function.parse-str.php ----- Original Message ----- From: "Knut H. Hassel Nielsen" <Knut.H.Hassel.Nielsen@idi.ntnu.no> To: "Mike Gifford" <mike@flora.org> Cc: <php-general@lists.php.net> Sent: Wednesday, April 04, 2001 6:12 PM Subject: Re: [PHP] Building an array from a URL Did you try to see if $HTTP_GET_VARS can help you ? Its an array of every variable posted by GET (the way you described) Else : Split the different key/values with the delimiter '&' and thereafter split the elements in the array by '=' But first split the string into page and variables : list( $page, $str ) = split("?","superRSS.phtml?150=1150&superRSS166=1166&superRSS168=1168&superRS S175=1188"); function make_arr_from_str( $str ) { $exp_arr = Explode( "&", $str ); $new_arr = Array(); for ( $i = 0 ; $i < count( $exp_arr ) ; $i++ ) { list( $key, $val ) = split( "=", $exp_arr[ $i ] ); $new_arr["$key"] = $val; } return $new_arr; } $array = make_arr_from_str( $str ); var_dump($array); On Wed, 4 Apr 2001, Mike Gifford wrote: > Hello, > > I'm trying to build an array out of data submitted from a URL. > > Essentially, I want to pull certain records out of a database which have been > selected on another form. > > The URL presently looks like this: > superRSS.phtml?150=1150&superRSS166=1166&superRSS168=1168&superRSS175=1188 > > I'd like to take these independent variables and merge them into a single array: > $array_superRSS = implode (":", $superRSS[]); > > So I can then pipe these values directly into another function: > > while ($array_superRSS) { > display_superRSS($array_superRSS[]); > } > > Obviously I'm missing a step or two here, but would really appreciate someone > filling in some of the gaps. > > Thanks! > > Mike > -- Knut ------ Knut H. Hassel Nielsen Principal Engineer / Avdelingsingeniør Norwegian University of Science and Technology / NTNU Department of Computer and Information Science / IDI N-7491 Trondheim, Norway Phone Office / Telefon jobb : (+47) 73 59 18 46 Fax Office / Telefax jobb : (+47) 73 59 17 33 Cell. Phone / Mobiltelefon : 91 59 86 06 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#47091) next »