HTTP for PHP

Source: Internet
Author: User

Http_build_query the request string after generating url-encoded

1. Using key-value pairs, associative arrays:

<?php$data = Array (' foo ' = ' bar ',              ' baz ' = ' boom ',              ' cow ' = ' milk ', '              php ' = ' hypertext ') Processor ');              echo Http_build_query ($data);/* Output:      

2, the use of digital subscript

<?php$data = Array (' foo ', ' Bar ', ' baz ', ' boom ', ' cow ' = ' milk ', ' php ' = ' hypertext processor ');              echo Http_build_query ($data);/* Output:      0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+ Processor*/echo http_build_query ($data, ' myvar_ ');/* Output:      

3. Using multidimensional arrays:

<?php$data = Array (' User ' =>array (' name ' = ' Bob Smith ', ' age ' =>47, ' Sex ' = ' M ', ' dob ' = ' 5/12/1956 '), ' pastimes ' =>array (' golf ', ' oper                                               A ', ' poker ', ' rap '), ' Children ' =>array (' Bobby ' =>array (' age ' =>12,                                               ' Sex ' = ' M '), ' Sally ' =>array (' age ' =>8,                                               ' Sex ' = ' F '), ' CEO '); Echo http_build_query ($data, ' flags_ ');/* Output: (Wrapping it for readability) user[name]=bob+smith&user[age]=47&user[sex]=m& amp;user[dob]=5%1f12%1f1956& pastimes[0]=golf&pastimes[1]=opera&pastimes[2]=poker&pastimes[3]= rap& children[bobby][age]=12&children[bobby][sex]=m&children[sally][age]=8& Children[sally][sex] =F&AMP;FLAGS_0=CEO Note: Only the number subscript element in the underlying array "CEO" obtains the prefix, the other number subscript element (Elements such as pastimes) do not need to be prefixed with a valid variable name.  */?>

4. Using objects

<?phpclass MyClass {  var $foo;  var $baz;    function MyClass () {    $this->foo = ' bar ';    $this->baz = ' boom ';  }} $data = new MyClass (); Echo http_build_query ($data);/* Output:      

HTTP for PHP

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.