PHP preg_replace expression to remove URL parameter after question mark

I wanted to remove all occurrences of specific pattern of a parameter from a URL using preg_expression.

$url = "http://phpblogspot.com/link.php?r=test5&id=3726&location=24&sublocation=";
$url2 = substr($url, 0, strpos($url, '?'));
echo $url2;

Leave a Reply