A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearPHP function to build query string from array - page 1
User InfoPosts
PHP function to build query string from array#1
I(m looking for the name of the PHP function to build a query string from an array of key value pairs. Please note, I am looking for the built in PHP function to do this, not a homebrew one (that(s all a google search seems to return). There is one, I just can(t remember its name or find it on php.net. IIRC its name isn(t that intuitive.

posted date: 2008-12-30 08:49:00


Re: PHP function to build query string from array#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-30 08:49:01


Re: PHP function to build query string from array#3
I(m not aware of a builtin function, but there is the PECL class http://uk.php.net/manual/en/class.httpquerystring.php

posted date: 2008-12-30 08:51:00


Re: PHP function to build query string from array#4
Implode will combine an array into a string for you, but to make an SQL query out a kay/value pair you(ll have to write your own function.

posted date: 2008-12-30 08:52:00


Re: PHP function to build query string from array#5
Tried that but it won't work. I'm trying to build an http query string which requires both the keys and the values from the array, implode can't do this.

posted date: 2008-12-30 09:00:00


Re: PHP function to build query string from array#6
Wish I'd known about that function a long time ago. Heh.

posted date: 2008-12-30 09:17:00


Re: PHP function to build query string from array#7
I see, wasn't sure if you meant an SQL query string or a http query string.

posted date: 2008-12-30 13:05:00


Re: PHP function to build query string from array#8
Never knew about this. Super!

posted date: 2011-03-15 15:27:00


Re: PHP function to build query string from array#9
Here(s a simple php4-friendly implementation:/*** Builds an http query string.* @param array $query // of key value pairs to be used in the query* @return string // http query string.**/function build_http_query( $query ){ $query_array = array(); foreach( $query as $key => $key_value ){ $query_array[] = urlencode( $key ) . (=( . urlencode( $key_value ); } return implode( (&(, $query_array );}

posted date: 2011-05-13 11:54:00


Re: PHP function to build query string from array#10
I guess you didn't see the accepted answer?

posted date: 2011-05-13 12:09:00


Re: PHP function to build query string from array#11
this is a php4 version.

posted date: 2011-05-13 13:08:00


Re: PHP function to build query string from array#12
but for inverse this work, you can use :void parse_str(str $input, array $output);//for example:$str = "first=value&arr[]=foo+bar&arr[]=baz";parse_str($str);echo $first; // valueecho $arr[0]; // foo barecho $arr[1]; // bazparse_str($str, $output);echo $output[(first(]; // valueecho $output[(arr(][0]; // foo barecho $output[(arr(][1]; // bazGood luck.

posted date: 2012-05-10 22:39:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.