note 33278 deleted from reserved.variables by sniper
| From: | sniper@php.net | Date: | Tue, 21 Oct 2003 19:43:19 +0000 |
| Subject: | note 33278 deleted from reserved.variables by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59065@lists.php.net to get a copy of this message | ||
Note Submitter: prophet@bestweb.net
----
Decided to rewrite the previous "replaceOnQuerystring" function listed on this page,
because it wasn't working for me :
function replaceOnQuerystring($changeArray)
{
$thisQuery = $_SERVER["QUERY_STRING"];
$queryArray = explode("&",$thisQuery);
$counter = 0;
foreach ($queryArray as $queryItem) // changes / modifications to existing.
{
if($counter != 0) // Make sure its not the 1st time around.
{
$newQuery .= '&'; // append a & to the query string, for the next var.
}
$querySegment = explode("=",$queryItem); // get the name and value into an array.
$varName = $querySegment[0]; // variable name
$varValue = $querySegment[1]; // variable value
if(isset($changeArray[$varName])) // is the var name listed in the changes?
{ // yes.
$newQuery .= $varName . '=' . $changeArray[$varName]; // add the changes to the new
query string.
unset($changeArray[$varName]); // remove from change array, so we don't repeat.
}
else
{ // no.
$newQuery .= $varName . '=' . $varValue; // leave it be, and add it to the new query.
}
$counter++; // up the counter so it knows to add a &.
}
foreach($changeArray as $changeItem => $changeValue) // loop though the changearray to clean up
any vars being added.
{
if($counter != 0)
{
$newQuery .= '&';
}
$newQuery .= $changeItem . '=' . $changeValue; // add it in.
unset($changeArray[$changeItem]); // unset it.
$counter++;
}
//return $_SERVER['PHP_SELF'] . '?' . $newQuery;
return $newQuery;
}