PHP uses Http_build_query () to construct a URL string (the Post parameter group transformation can be stitched into a GET request link)

Source: Internet
Author: User

<?PHP//Parse_str and Http_build_query use//use PARSE_STR to convert a URL string to an array of Key=>value$str= "Tn=monline_dg&ie=utf-8&bs=httpbuildurl&f=3&rsv_bp=1&wd=php+buildquery&rsv_sug3=17 &rsv_sug4=330&rsv_sug1=16&oq=php+build&rsv_sug2=0&rsp=0&inputt=8922 "; Parse_str($str,$arr); Var_export($arr); /*output: Array (' tn ' = ' monline_dg ', ' ie ' = ' utf-8 ', ' bs ' = ' httpbuildurl ', ' f ' = ' 3 ', ' RSV_BP ' = ' 1 ', ' wd ' = ' php buildquery ', ' rsv_sug3 ' = ' + ', ' rsv_sug4 ' + ' + ', ' rsv_sug1 ' = ' 16 ', ' OQ ' + ' PHP build ', ' rsv_sug2 ' = ' 0 ', ' rsp ' = ' 0 ', ' inputt ' = ' 8922 ',)*/    //use Http_build_query to convert an array of key=>value into a URL string$url=Http_build_query($arr); Echo($url); //Output: tn=monline_dg&ie=utf-8&bs=httpbuildurl&f=3&rsv_bp=1&wd=php+buildquery&rsv_sug3= 17&rsv_sug4=330&rsv_sug1=16&oq=php+build&rsv_sug2=0&rsp=0&inputt=8922?>

To put it simply, Http_build_query () is converting an array into a URL question mark, followed by a parameter string, and is automatically urlencode processed.

PHP uses Http_build_query () to construct a URL string (the Post parameter group transformation can be stitched into a GET request link)

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.