Phphttp_build_query implementation tutorial _ PHP Tutorial

Source: Internet
Author: User
Phphttp_build_query implementation tutorial. Phphttp_build_query implementation tutorial http_build_query (in PHP5) http_build_query-generate URL encoding query string description string http_build_query (array $ formdata [, string php http_build_query implementation tutorial

Http_build_query
(In PHP 5)

Http_build_query-generate URL encoding query string

Description
String http_build_query (array $ formdata [, string $ numeric_prefix [, string $ arg_separator])
Generate a URL encoded query string provided from the Lenovo (or index) array.

Parameters

Formdata
An array or object may contain attributes.

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

Numeric_prefix
If the numeric indicator is used for basic display and provides this parameter, this will be the basic display of the prepended numeric index content only.

This is a variable name permitted by law. data decoding is performed in 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

Version description
5.1.2 supplement the arg_separator parameter.
5.1.3 escape characters in square brackets.


Instance
For example, #1 simple use of 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 will 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' => '2017/123 '),
'Pastimes' => array ('golf', 'Opera ', 'poker', 'rap '),
'Children '=> array ('Bob' => array ('age' => 12,
'Sex '=>'m '),
'Sally '=> array ('age' => 8,
'Sex' => 'F ')),
'CEOs ');

Echo http_build_query ($ data, 'flags _');


Http://www.bkjia.com/PHPjc/445454.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445454.htmlTechArticlephp http_build_query implementation tutorial http_build_query (PHP 5) http_build_query-generate URL encoding query string description string http_build_query (array $ formdata [, 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.