1function strip_param_from_url( $url, $param ) {
2 $base_url = strtok($url, '?'); // Get the base url
3 $parsed_url = parse_url($url); // Parse it
4 $query = $parsed_url['query']; // Get the query string
5 parse_str( $query, $parameters ); // Convert Parameters into array
6 unset( $parameters[$param] ); // Delete the one you want
7 $new_query = http_build_query($parameters); // Rebuilt query string
8 return $base_url.'?'.$new_query; // Finally url is ready
9}
10// Usage
11echo strip_param_from_url( 'http://url.com/search/?location=london&page_number=1',
12 'location' )