Posted By

elightbo on 01/22/10


Tagged

php String querystring query


Versions (?)

Remove a Query String Key=>Value


 / Published in: PHP
 

URL: http://davidwalsh.name/php-remove-variable?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Bludice+%28David+Walsh+Blog+%3A%3A+PHP%2C+CSS%2C+MooTools%2C+and+Everything+Else%29&utm_content=Google+Reader

  1. /* the function */
  2. function remove_querystring_var($url, $key) {
  3. $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
  4. $url = substr($url, 0, -1);
  5. return $url;
  6. }
  7.  
  8. /* usage */
  9. //pretending this page is

Report this snippet  

You need to login to post a comment.