You can use it to get the url.
$parsed = parse_url($url);
$finalUrl= $parsed['scheme']. '://'. $parsed['host']. $parsed['path'];
The main question was Remove parameters from string containing URL
So here on first line,
the url is parsed with parse_url() method it will return
and array with four element
first index will be scheme
second one will be host
third one will be path
fourth one will be query
now on second line,
final url is build without the query parameter.
For safe side coading you can add condition to check valid url at first.
if (filter_var($url, FILTER_VALIDATE_URL)) {
//-- valid url
}
so final code will be.
if (filter_var($url, FILTER_VALIDATE_URL)) {
//-- valid url
$parsed = parse_url($url);
$finalUrl= $parsed['scheme']. '://'. $parsed['host']. $parsed['path'];
}
Thanks all