parse_url 与http_build_query

<?php
$data = array('foo'=>'bar',
        'baz'=>'boom',
        'cow'=>'milk',
        'php'=>'hypertext processor'
);
$url = "http://abc.php?";

$param = http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor

$url = $url.$param;

$arr = parse_url($url);

//{ ["scheme"]=> string(4) "http" ["host"]=> string(7) "abc.php" ["query"]=> string(49) //"foo=bar&baz=boom&cow=milk&php=hypertext+processor" }


$query = $arr['query'];

//"foo=bar&baz=boom&cow=milk&php=hypertext+processor" 有"+" http_build_query 自动//urlencode编码

$query = urldecode($query);

return $query; //"foo=bar&baz=boom&cow=milk&php=hypertext processor"
?>


你可能感兴趣的:(parse_url 与http_build_query)