$rawurl = "https://www.collectivesolver.com/36304/how-to-use-recursive-function-in-php";
$url = parse_url($rawurl);
print_r($url);
$domain = preg_replace('#^(?:.+?\\.)+(.+?\\.(?:co\\.uk|com|net))#', '$1', $url['host']);
echo $domain;
/*
run:
Array
(
[scheme] => https
[host] => www.collectivesolver.com
[path] => /36304/how-to-use-recursive-function-in-php
)
www.collectivesolver.com
*/