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); php

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


$query = $arr['query']; 編碼

//"foo=bar&baz=boom&cow=milk&php=hypertext+processor" 有"+" http_build_query 自動//urlencode編碼 url

$query = urldecode($query); return $query; //"foo=bar&baz=boom&cow=milk&php=hypertext processor" ?>
相關文章
相關標籤/搜索