title: php; remove single variable value pair from querystring
body: <p>I have a page that lists out items according to numerous parameters ie variables with values.  </p>
  
  <pre><code>listitems.php?color=green&amp;size=small&amp;cat=pants&amp;pagenum=1 etc.
  </code></pre>
  
  <p>To enable editing of the list, I have a parameter edit=1 which is appended to the above querystring to give:</p>
  
  <pre><code>listitems.php?color=green&amp;size=small&amp;cat=pants&amp;pagenum=1&amp;edit=1
  </code></pre>
  
  <p>So far so good.</p>
  
  <p>WHen the user is done editing, I have a link that exits edit mode.  I want this link to specify the whole querystring--whatever it may be as this is subject to user choices--except remove the edit=1.</p>
  
  <p>When I had only a few variables, I just listed them out manually in the link but now that there are more, I would like to be able programmatically to just remove the edit=1.</p>
  
  <p>Should I do some sort of a search for edit=1 and then just replace it with nothing? </p>
  
  <pre><code>$qs = str_replace("&amp;edit=1, "", $_SERVER['QUERY_STRING']);
  &lt;a href='{$_SERVER['PHP_SELF']}?{$qs}'&gt;return&lt;/a&gt;;
  </code></pre>
  
  <p>Or what would be the cleanest most error-free way to do this.</p>
  
  <p>Note: I have a similar situation when going from page to page where I'd like to take out the pagenum and replace it with a different one.  There, since the pagenum varies, I cannot just search for pagenum=1 but would have to search for <code>pagenum =$pagenum</code> if that makes any difference.</p>
  
  <p>Thanks.</p>