龍巖易富通網(wǎng)絡(luò)科技有限公司

龍巖小程序開發(fā),龍巖分銷系統(tǒng)

php parse_str與http_build_query的使用

2017.10.27 | 1689閱讀 | 0條評(píng)論 | php

<?php

//parse_str與http_build_query的使用


//使用parse_str將url字符串轉(zhuǎn)變?yōu)閗ey=>value的數(shù)組

$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的數(shù)組轉(zhuǎn)變?yōu)閡rl字符串

$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


?>


贊 (

發(fā)表評(píng)論