NameSilo

Remove variable from $_SERVER['QUERY_STRING']

Spaceship Spaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
I need to remove the variable $m from my querystring... the querystring is variable, and $m is never always in the same place, and never the same variable.

I want to make a link from search.php?m=blah&q=blah2 etc... to search.php?m=something_else_now&q=blah2 < same again. Now, there could potentially be hundreds of variables in my querystring, and $m could be anywhere in there, so I can't just take the first x letters off. Also the value of $m varys in length depending on the the user's preferences.

Is there any way I can take the $m value out of the querystring?

Thanks
Tom

Hey, I put my mind to it, and I got it! :)

if anyone wants the code: here it is:

PHP:
$querystring = explode("&",$_SERVER['QUERY_STRING']);
                $qs_nos = 0;
                
                $qs_final = "?";
                while(isset($querystring[$qs_nos])){
                  if(!ereg("m=",$querystring[$qs_nos])){ // change the "m=" to "var_to remove="
                    $qs_final .= $querystring[$qs_nos]."&";
                  }
                  $qs_nos++;
                }

$qs_final is the variable that holds the new querystring with your var removed!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
That was on the lines of what i was thinking also. Thanks for sharing.
 
0
•••
alternatively you could do the following:-

PHP:
$name_of_varialbe = 'b';
unset($_GET[$name_of_varialbe]);
$string = '?';
$counted = count($_GET);
$count = 0;
foreach ($_GET as $key=>$value)
{
	$string .=$key.'='.$value;
	$count++;
	if ($count!=$counted)
	{
		$string .= '&';
	}
}

$name_of_varialbe is the variable which will hold the name of the variable you wish to be removed. $string is the result string after it has been removed.
 
0
•••
that maybe better for me, as it won't accidentally cut a string in half if the user uses a "m=" in the middle of a string (as if... lol - better safe than sorry)
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back