title: PHP Query String Manipulation
body: <p>Any one have the ultimate PHP function(s) to add/remove parameters from a query string?
  It needs to handle all possible cases, Ive seen ones that handle some cases, but not all.</p>
  
  <p>Some example cases:</p>
  
  <ul>
  <li><a href="http://mysite.com?param1=1&amp;param2=2" rel="nofollow">http://mysite.com?param1=1&amp;param2=2</a></li>
  <li>http://www.mysite.com/?param1[]=1&amp;param1[]=2</li>
  <li><a href="ftp://user:pass@mysite.com/files/uploads/?param1=1&amp;param2=2" rel="nofollow">ftp://user:pass@mysite.com/files/uploads/?param1=1&amp;param2=2</a></li>
  <li>/?param1=1&amp;param2=2</li>
  <li>/page.html?param1=1</li>
  <li>/dir/page.html?test=1&amp;bla=2</li>
  <li>/dir/page.html?param1=1#jump_to_bottom</li>
  </ul>
  
  <p>It should ideally be something like:</p>
  
  <pre><code>function add_get_param($uri, $name, $value = null) { ... }
  function remove_get_param($uri, $name) { ... }
  </code></pre>
  
  <p>Some example tests:</p>
  
  <pre><code>$var = add_get_param('http://mysite.com?param1=1&amp;param2=2', 'param3', 3);
  // http://mysite.com?param1=1&amp;param2=2&amp;param3=3
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>$var = add_get_param('/dir/page.html?param1=1&amp;param2=2#jump_to_bottom', 'param3');
  // /dir/page.html?param1=1&amp;param2=2&amp;param3#jump_to_bottom
  </code></pre>
  
  <p>etc...</p>
  
  <p><strong>Alright, I wrote my own functions:</strong></p>
  
  <p>PHP: <a href="http://pastebin.org/170157" rel="nofollow">http://pastebin.org/170157</a>
  jQuery: <a href="http://pastebin.org/169981" rel="nofollow">http://pastebin.org/169981</a></p>