Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,880 questions

51,806 answers

573 users

How to generate URL-encoded query string in PHP

5 Answers

0 votes
// string http_build_query ( mixed $query_data [, string $numeric_prefix 
// [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )

$q = array('user'=>'master_splinter',
           'password'=>'12345',
           'email'=>'ms@ninjaturtles.com');

echo http_build_query($q) . "<br />";

/*
run:

user=master_splinter&password=12345&email=ms%40ninjaturtles.com

*/

 



answered Jun 28, 2016 by avibootz
0 votes
// string http_build_query ( mixed $query_data [, string $numeric_prefix 
// [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )

$q = array('user'=>'master_splinter',
           'password'=>'12345',
           'email'=>'ms@ninjaturtles.com');

echo http_build_query($q, '', '&amp;');

/*
run:

user=master_splinter&amp;password=12345&amp;email=ms%40ninjaturtles.com

*/

 



answered Jun 28, 2016 by avibootz
0 votes
// string http_build_query ( mixed $query_data [, string $numeric_prefix 
// [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )

$q = array('c++', 'c', 'java', 'javascript', 'c#' => 'microsoft', 'php' =>'open source');

echo http_build_query($q);


/*
run:

0=c%2B%2B&1=c&2=java&3=javascript&c%23=microsoft&php=open+source

*/

 



answered Jun 28, 2016 by avibootz
0 votes
// string http_build_query ( mixed $query_data [, string $numeric_prefix 
// [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )

$q = array('c++', 'c', 'java', 'javascript', 'c#' => 'microsoft', 'php' =>'open source');

echo http_build_query($q, 'q_prefix_');


/*
run:

q_prefix_0=c%2B%2B&q_prefix_1=c&q_prefix_2=java&q_prefix_3=javascript&c%23=microsoft&php=open+source

*/

 



answered Jun 28, 2016 by avibootz
0 votes
// string http_build_query ( mixed $query_data [, string $numeric_prefix 
// [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )

$q = array('user'=>array('name'=>'Dan',
                         'age'=>51,
                         'sex'=>'M'),
           'hobbies'=>array('programming', 'sci-fi movies', 'music'),
           'partner'=>array('Margot'=>array('age'=>47,
                                            'sex'=>'F')),
           'entrepreneur');

echo http_build_query($q);


/*
run:

user%5Bname%5D=Dan&user%5Bage%5D=51&user%5Bsex%5D=M&hobbies%5B0%5D=programming&hobbies%5B1%5D=sci-fi+movies&hobbies%5B2%5D=music&partner%5BMargot%5D%5Bage%5D=47&partner%5BMargot%5D%5Bsex%5D=F&0=entrepreneur

*/

 



answered Jun 28, 2016 by avibootz

Related questions

1 answer 244 views
1 answer 175 views
175 views asked Jul 16, 2016 by avibootz
1 answer 245 views
2 answers 761 views
2 answers 325 views
325 views asked Aug 12, 2015 by avibootz
2 answers 220 views
...