I've been searching all day, trying different functions, regular expressions, etc., but nothing I've tried seems to work fully,

so I've decided to let someone else have a go...
What I want to do is check for uniqueness of the domain of a submitted site. I do not even want to allow subdomains.
So far I have this:
PHP Code:
$url_in_db = 'http://www.domain.tld/thispage.html';
$submitted_url = 'http://www.domain.tld/anotherpage.html';
$parsedurl = parse_url($submitted_url);
$get_the_hostname = $parsedurl["host"];
if (strstr ($url_in_db, $get_the_hostname))
echo "match found";
else
echo "no match";
That works, but it doesn't do exactly what I want it to do, because although it finds a match if the 'www.' is left off, it doesn't find a match on a subdomain entry like 'http://web.domain.tld/thispage.html'
There is an example at php.net to get the hostname:
PHP Code:
preg_match('@^(?:http://)?([^/]+)@i', "http://www.domain.tld/index.html", $matches);
$host = $matches[1];
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
This doesn't work for the '.co.uk', '.com.au', etc TLDs as it returns the last two elements of the domain, nor would it match any 'https://' URLs
So it is over to the PHP gurus at

& |Jim
There is no rush on this, but if I could have a solution by Thursday 12th Oct, that would be great
Note - As you may have guessed, the '$url_in_db' is stored in a MySQL table, in case a function exists in a query expression that I may have missed.