In my Github I've created a gist with a function to do operations like this in a reusable way. What's more, I preferred not to use regular expression, as these usually cost more in terms of performance.
This function allows you to remove, replace or add parameters to a particular url. If it already has Query String, it will be replaced or added.
See:
function url_replace_query($url, array $parameters)
{
$parts = parse_url($url) + [
'scheme' => 'http',
'query' => NULL,
'path' => NULL,
];
if (! isset($parts['host'])) return false;
parse_str($parts['query'], $query);
$parameters += $query;
$newQueryString = http_build_query($parameters);
return $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '?' . $newQueryString;
}
You can use it like this:
$url_sem_ordem = url_replace_query("http://www.meudominio.com.br/pagina.php?campo=teste&ordem=2&cor=azul", ['ordem' => null])
Result:
'http://www.meudominio.com.br/pagina.php?campo=teste&cor=azul'