標籤:自動 get 轉變 拼接 utf-8 val query UI div
<?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 ?>
簡單來說,http_build_query()就是將一個數群組轉換成url 問號?後面的參數字串,並且會自動進行urlencode處理。
PHP使用http_build_query()構造URL字串的方法(可將POST參數群組轉換拼接成GET請求連結)