Cool, here's some more new stuff. It probably needs some adjustments and such, but I think it at least "almost" works.

You would just need to add/remove the second level domains that you want to be matched. Of course it could be made so you could add/remove these through a form or something, but this is just an example of how or "if" it even functions for now.
PHP Code:
<?php
function getdomain($url) {
$url = strtolower($url);
$slds =
'\.co\.uk|\.me\.uk|\.net\.uk|\.org\.uk|\.sch\.uk|
\.ac\.uk|\.gov\.uk|\.nhs\.uk|\.police\.uk|
\.mod\.uk|\.asn\.au|\.com\.au|\.net\.au|\.id\.au|
\.org\.au|\.edu\.au|\.gov\.au|\.csiro\.au';
preg_match (
"/^(http:\/\/|https:\/\/|)[a-zA-Z-]([^\/]+)/i",
$url, $matches
);
$host = $matches[2];
if (preg_match("/$slds$/", $host, $matches)) {
preg_match (
"/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/",
$host, $matches
);
}
else {
preg_match (
????: NamePros.com http://www.namepros.com/programming/53456-parse-a-url-php-return-domain.html
"/[^\.\/]+\.[^\.\/]+$/",
$host, $matches
);
}
return "{$matches[0]}";
}
$url1 = "http://WWW.NAMEPROS.COM/showthread.php?t=53456";
$url2 = "https://www.direct.gov.uk/Homepage/fs/en";
$url3 = "http://horribly.long.subdomains.file.net/index.php";
$url4 = "http://66.98.205.16/tester"; # just for fun
$url5 = "http://WWW.somedomain.pros.com.au/dir/file.html";
$url6 = "https://www.www2.hosting.org.uk/home/index.php?file=1";
$url7 = "http://sub.sub2.sub3.sub4.cars.com.au/index.php";
$url8 = "http://66.227.205.43/files/index.pl"; # just for fun2
$url9 = "http://WWW.BIGDOMAIN.co.uk/long/file/dir/path/enter.htm";
$url10 = "https://www.er.doctors.net.uk/";
$url11 = "http://number.2.3.4.711.com/";
$url12 = "http://66.98.205.16/tester/ip.a/files"; # just for fun3
echo "<br>url: $url1 <Br>domain: ".getdomain($url1)."<br>";
echo "<br>url: $url2 <Br>domain: ".getdomain($url2)."<br>";
echo "<br>url: $url3 <Br>domain: ".getdomain($url3)."<br>";
echo "<br>url: $url4 <Br>domain: ".getdomain($url4)."<br>";
echo "<br>url: $url5 <Br>domain: ".getdomain($url5)."<br>";
echo "<br>url: $url6 <Br>domain: ".getdomain($url6)."<br>";
echo "<br>url: $url7 <Br>domain: ".getdomain($url7)."<br>";
????: NamePros.com http://www.namepros.com/showthread.php?t=53456
echo "<br>url: $url8 <Br>domain: ".getdomain($url8)."<br>";
echo "<br>url: $url9 <Br>domain: ".getdomain($url9)."<br>";
echo "<br>url: $url10 <Br>domain: ".getdomain($url10)."<br>";
echo "<br>url: $url11 <Br>domain: ".getdomain($url11)."<br>";
echo "<br>url: $url12 <Br>domain: ".getdomain($url12)."<br>";
?> The current results from the above example url's, so you can get an idea, I think would look something like this:
url:
http://horribly.long.subdomains.file.net/index.php
domain: file.net
url:
http://66.98.205.16/tester
domain:
url:
http://WWW.somedomain.pros.com.au/dir/file.html
domain: pros.com.au
url:
https://www.www2.hosting.org.uk/home/index.php?file=1
domain: hosting.org.uk
url:
http://sub.sub2.sub3.sub4.cars.com.au/index.php
domain: cars.com.au
url:
http://66.227.205.43/files/index.pl
domain:
url:
http://WWW.BIGDOMAIN.co.uk/long/file/dir/path/enter.htm
domain: bigdomain.co.uk
url:
https://www.er.doctors.net.uk/
domain: doctors.net.uk
url:
http://number.2.3.4.711.com/
domain: 711.com
url:
http://66.98.205.16/tester/ip.a/files
domain: