Http_build_query string concatenation

Source: Internet
Author: User

Http_build_query string concatenation

Generates a urlencode after the request string.

1. Convert an array to a string after the URL question mark (?)

1<?PHP2   $date=Array(3' Name ' = ' Tane ',4' Sex ' =>1,5' Job ' = ' officer '6' Text ' = ' Hello World '7   );8   Echo Http_build_query($date);9   //Output Name=tane&sex=1&job=officer&text=hello+worldTen?>

2.http_build_query () Adding a digital subscript

$data Array (' name ', ' Tane ', ' sex ',  ' job ' = ' officer ', ' text ' = ' Hello World ');    Echo Http_build_query ($date, ' remot_ ');    // Output Remot_0=name&remote_1=tane&remot_2=sex&job=officer&text=hello+world

3.http_build_query () using a complex array

<?PHP$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 ' <br> '), ' CEO '); Echo Http_build_query($data, ' Flags_ '); /*Output: (Wrapping it for readability) user[name]=bob+smith&user[age]=47&user[sex]=m&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&flags_0=ceo Note: Only the number in the underlying array  The subscript element "CEO" obtains the prefix, other numeric subscript elements (such as elements under pastimes) do not need to be prefixed with a valid variable name. */?>

4.http_build_query () Working with objects

<?PHPclassMyClass {var $foo; var $baz; functionMyClass () {$this->foo = ' Bar '; $this->baz = ' boom '; }    }    $data=NewMyClass (); Echo Http_build_query($data); /*Output: Foo=bar&baz=boom*/?>

Http_build_query string concatenation

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.