1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php
$str = 'http://test.com/testdir/index.php?param1=10¶m2=20¶m3=30¶m4=40¶m5=50¶m6=60';
$arr = parse_url($str); var_dump($arr);
$arr_query = convertUrlQuery($arr['query']); var_dump($arr_query);
var_dump(getUrlQuery($arr_query));
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; } ?>
|