1. 程式人生 > >PHP獲取地址url引數值

PHP獲取地址url引數值

$url = 'http://apps.ebrun.com/dmp_api/get_keyword_report.php?k=進口電商&p=北京&c=東城&st=2017-04-01&et=2017-04-30'; 
$arr = parse_url($url);
$arr_query = convertUrlQuery($arr['query']);
var_dump($arr_query);
var_dump(getUrlQuery($arr_query));die;


function convertUrlQuery($query) {
	$queryParts = explode('&', $query);
	$params = array();
	foreach ($queryParts as $param) {
		$item = explode('=', $param);
		$params[$item[0]] = $item[1];
	}
	return $params;
}
function getUrlQuery($array_query) {
	$tmp = array();
	foreach($array_query as $k=>$param) {
		$tmp[] = $k.'='.$param;
	}
	$params = implode('&',$tmp);
	return $params;
}