Ok, I have started the following code but I don't know how to strip out the query string...

PHP Code:
<?php $query $_GET['query'];
$oldurl = echo $_SERVER['PHP_SELF']; //For example: http://www.mysite.com/currentpage.php?query=whatever
if ($query != '') { 
    
$newurl $oldurl//BUT REMOVING THE QUERYSTRING - How do I do this?
    
Header"HTTP/1.1 301 Moved Permanently" ); 
    
Header"Location: $newurl); 
}    
?>