PHP Http_build_query Patchwork Array

Source: Internet
Author: User
PHP http_build_query Stitching Array

?

Http_build_query

(PHP 5)

http_build_query?—? request string after generating Url-encode

Description

string? Http_build_query? (? array? $formdata ? [,? string? $numeric _prefix ?] )

Generates a Url-encode request string using the given array of associations (or subscripts). Parameters? formdata? can be an array or an object that contains properties. One? formdata? An array can be a simple one-dimensional structure or an array of arrays (which in turn can contain other arrays). What if a numeric subscript is used in the underlying array? numeric_prefixparameter, this parameter value will be prefixed with the number subscript element in the underlying array. This is to get a valid variable name when PHP or other CGI programs decode the data later.

Note:

Use the arg_separator.output? to separate the parameters.

Example #1? http_build_query ()? Using the example

$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
?>

Example #2? http_build_query ()? Use the element with a number subscript

$data? =?array (' foo ',?' Bar ',?' Baz ',?' boom ',?' cow '?=>?' Milk ',?' php '?=' Hypertext?processor ');
??????????????
Echo? Http_build_query ($data );

?
echo? Http_build_query ($data,? ' Myvar_ ' );

?>


=======================================================================================


A simple understanding of these two functions

Parse_str is to convert a URL into an array after the argument

Array Parse_str (Url,arr)


Parse_url is to parse a full URL into an array

Array parse_url (string url)


Http_build_query is the conversion of an array into a URL, followed by a string of arguments that are automatically urlencode processed

String Http_build_query (Array formdata [, String Numeric_prefix])

Add subscript to the array without specifying a key or a key as a number

  • 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.