Remove all arguments from query string in URL except one


/ Published in: PHP
Save to your folder(s)

Remove all arguments from query string in URL except one


Copy this code and paste it in your HTML
  1. $url = $_SERVER['PHP_SELF'];
  2.  
  3. $url_parts = parse_url($url);
  4.  
  5. $new_url = $url_parts['scheme'].'://'.$url_parts['host'].$url_parts['path'];
  6.  
  7. if (isset($url_parts['query'])) {
  8.  
  9. parse_str($url_parts['query'], $query_arguments);
  10. $f = create_function('$a','return $a==\'page\';');
  11. $query_arguments = array_flip(array_filter(array_flip($query_arguments), $f));
  12.  
  13. $new_url .= '?'.http_build_query($query_argumenys);
  14.  
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.