Maybe the parse_url function could help, here ?
In your case, with those URLs, the following portion of code :
echo parse_url('http://site.com/hello.php', PHP_URL_HOST) . '
';
echo parse_url('http://site.com.uk/hello.php', PHP_URL_HOST) . '
';
echo parse_url('http://subdomain.site.com/hello.php', PHP_URL_HOST) . '
';
echo parse_url('http://subdomain.site.com.uk/hello.php', PHP_URL_HOST) . '
';
echo parse_url('http://www.champa.kku.ac.th/hello.php', PHP_URL_HOST) . '
';
Gives this output :
site.com
site.com.uk
subdomain.site.com
subdomain.site.com.uk
www.champa.kku.ac.th