note 23167 deleted from reserved.variables by sniper

From: Date: Tue, 21 Oct 2003 19:45:42 +0000
Subject: note 23167 deleted from reserved.variables by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59082@lists.php.net to get a copy of this message
Note Submitter: webmaster@oscillate.net ---- // Replaces or removes elements from a querystring // changeArray should take the form array('p' => 'stock','tc' => null) etc // will return the same querystring, with any elements modded/removed/added function replaceOnQuerystring($changeArray) { $thisQuery = $_SERVER["QUERY_STRING"]; $queryArray = explode("&",$thisQuery); $counter = 1; foreach ($queryArray as $queryItem) { $querySegment = explode("=",$queryItem); if ($counter>1) { $tempString .= "&"; } if (isset($changeArray[$querySegment[0]])) { // Querystring key exists in changeArray - replace it (otherwise ignore it) // Remove element from changeArray for clearup afterwards $tempString .= $querySegment[0] . "=" . $changeArray[$querySegment[0]]; unset($changeArray[$querySegment[0]]); } else { // Querystring key doesn't exist in changeArray if (array_key_exists($querySegment[0],$changeArray)) { unset($changeArray[$querySegment[0]]); } else { $tempString .= $querySegment[0] . "=" . $querySegment[1]; } } $counter += 1; } // Add on end any leftovers in changeArray: while (list ($key, $val) = each ($changeArray)) { if ($val) { if ($counter>1) { $tempString .= "&"; } $tempString .= $key."=".$val; } } return $tempString; }

« previous php.notes (#59082) next »