龙岩易富通网络科技有限公司

龙岩小程序开发,龙岩分销系统

php parse_str与http_build_query的使用

2017.10.27 | 1714阅读 | 0条评论 | php

<?php

//parse_str与http_build_query的使用


//使用parse_str将url字符串转变为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);


/*

输出:

array (

  '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',

)

*/


//使用http_build_query将key=>value的数组转变为url字符串

$url = http_build_query($arr);

echo($url);


//输出: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


?>


赞 (

发表评论