<?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
"http://example.uk", $matches);
$host = $matches[0];
// get last two segments of host name
preg_match('/([^.]+)\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";