http_build_query

PHP使用http_build_query()构造URL字符串的方法(可将POST参数组转换拼接成GET请求链接)

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处理。

你可能感兴趣的:(http_build_query)