<?php
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
"http://example.uk", $matches);
$host = $matches[2];
// get last two segments of host name
preg_match('/([^.]+)\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
Warning: Undefined array key 2 in /in/E03kA on line 6
Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /in/E03kA on line 9
Warning: Undefined array key 0 in /in/E03kA on line 10
domain name is:
Output for 8.0.0 - 8.0.30
Warning: Undefined array key 2 in /in/E03kA on line 6
Warning: Undefined array key 0 in /in/E03kA on line 10
domain name is: