# # This function redraws the current URI past the ? mark, replacing a given get variable with its new value # .... or adding the desired get variable and its value at the end. # function munge_uri($variable_to_munge="", $query="") { if (strlen($query) < 1) { global $QUERY_STRING; $query = $QUERY_STRING; } if (substr($query, 0, 1) == "?") { $query = substr($query, 1, strlen($query)-1); } $buf = ""; $vars = split("&", $query); #print_r($vars); $middle = strpos($variable_to_munge, "="); foreach ($vars as $var) { if ( substr($var, 0, $middle) == substr($variable_to_munge, 0, $middle) ) { # we don't add it here... because if a munged variable doesnt previously exist, we still want to add it at the end. } else { $buf = $buf . $var . "&"; } } #add the replacement variable here... so it will show even if it is new $buf = $buf . $variable_to_munge; # we need a ?, but we don't want to have ?????? buildup if we call this repeatedly on a string. if (substr($buf, 0, 1) != "?") { $buf = "?" . $buf; } return $buf; }