PHP http_build_query Implementation Tutorial _php Tutorial

Source: Internet
Author: User
PHP Http_build_query Implementation Tutorial

Http_build_query
(in PHP 5)

Http_build_query-Generate URL-encoded query string

Describe
String Http_build_query (array $ formdata [, String $ numeric_prefix [, String $ arg_separator]])
Generates a URL-encoded query string from a Lenovo (or indexed) array.

Parameters

Formdata
may be an array or an object containing an attribute.

The form of an array may be a simple one-dimensional structure, or an array of arrays (who may also contain other arrays).

Numeric_prefix
If the number indicator is used for the base display and provides this parameter, this will be the basis of the prepended's digital index content only.

This is the law allowed for variable names when data is decoded on PHP or other CGI applications.

Arg_separator
Arg_separator.output is used for separate arguments, unless this parameter is specified and then used.


return value
Returns a URL-encoded string.

Modify

Release Notes
5.1.2 Arg_separator parameter supplement.
5.1.3 is escaped inside the square brackets.


Instance
For example # 1 easy to use Http_build_query ()

$data = Array (' foo ' = ' bar ',
' Baz ' = ' boom ',
' cow ' = ' milk ',
' php ' = ' hypertext processor ');

echo Http_build_query ($data); Foo=bar&baz=boom&cow=milk&php=hypertext+processor
Echo http_build_query ($data, ', ' & '); Foo=bar&baz=boom&cow=milk&php=hypertext+processor

?>
Example #2 http_build_query () with numerically index elements.

$data = Array (' foo ', ' Bar ', ' baz ', ' boom ', ' cow ' = ' milk ', ' php ' = ' hypertext processor ');

echo Http_build_query ($data). "N";
Echo http_build_query ($data, ' myvar_ ');
?>
The above example would output:

0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor
Myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor
Example #3 Http_build_query () with complex arrays

$data = Array (' User ' =>array (' name ' = ' Bob Smith '),
' Age ' =>47,
' Sex ' = ' M ',
' DOB ' = ' 5/12/1956 '),
' Pastimes ' =>array (' Golf ', ' opera ', ' Poker ', ' rap '),
' Children ' =>array (' Bobby ' =>array (' age ' =>12,
' Sex ' = ' M '),
' Sally ' =>array (' age ' =>8,
' Sex ' = ' F '),
' CEO ');

Echo http_build_query ($data, ' flags_ ');


http://www.bkjia.com/PHPjc/445454.html www.bkjia.com true http://www.bkjia.com/PHPjc/445454.html techarticle php http_build_query Implementation Tutorial Http_build_query (PHP 5) http_build_query-Generate URL-encoded query string description string Http_build_query (array $ formda Ta [, String ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.