2 complex URLs
$url="https://www.example.co.uk/page/section/younameit"; or $url="https://example.co.uk/page/section/younameit";
To get "www.example.co.uk":
$host=parse_url($url, PHP_URL_HOST);
To get only example.co.uk
$parts = explode('www.',$host); $domain = $parts[1]; // ...or... $domain = ltrim($host, 'www.')
If your URL includes "www." or not, you get the same end result, that is, "example.co.uk"
Voila!
user3251285
source share