If the URL that you are trying to remove the query string from is the current URL of the PHP script, you can use one of the previously mentioned methods. If you just have a string variable with a URL in it and you want to strip off everything past the '?' you can do:
Inspired by the comment of @MitMaro, I wrote a small benchmark to test the speed of solutions of @Gumbo, @Matt Bridges and @justin the proposal in the question:
Its the fastest (see below), and handles urls without a '?' properly.
To take a url+querystring and remove just one variable (without using a regex replace, which may be faster in some cases), you might do something like:
basename($_SERVER['REQUEST_URI']) returns everything after and including the '?',
In my code sometimes I need only sections, so separate it out so I can get the value of what I need on the fly.
Not sure on the performance speed compared to other methods, but it's really useful for me.