I have an array of domain names, like:
array(
'http://example.co.uk/foo/bar',
'http://www.example.com/foo/bar',
'http://example.net/foo/bar')
And so on.
I am using
parse_url($url, PHP_URL_HOST);
to trim everything and just keep the domain name and it's working partly however, it's keeping the www part if it exists. How can I remove the 'www' if it exists. I tried to explicitly remove it from the domain name in the array, but when it resolves it reverts back to www.example.com.
So I'd like to return:
www.example.com/foo/bar > example
www.example.co.uk/foo/bar > example
example.com/foo/bar > example
example.net/foo/bar > example