For example, i have this URL:
Code: Select all
domain.net/folder/file.php?x=2&y=3&z=1
Code: Select all
x=2&z=1
Code: Select all
domain.net/folder/file.php?x=2&y=3&z=1
Code: Select all
x=2&z=1
Code: Select all
// Parse out url query string into an associative array
// @param $url String
// @return Array
function queryToArray($url){
$qry = parse_url($url, PHP_URL_QUERY);
parse_str($qry, $re);
return $re;
}
$url ='domain.net/folder/file.php?x=2&y=3&z=1';
$ar_qry = queryToArray($url);
//to see the array
var_export($ar_qry); // array('x'=>'2', 'y'=>'3', 'z'=>'1')
//rebuild and show query string wthout the $except parameter
$except ='y';
unset($ar_qry[$except]);
$qry = http_build_query($ar_qry);
echo $qry; //x=2&z=1