Check Simaple Code
You can get host, subdomain, domain, extension
$urls = array("https://www.face.com","www.asdasd.asd","sasdas.com/asdas","sdfsdf.sdf","https://app.abcdlink.com/user/test/");
Function :-
function getDomainname($a)
{
$r = "(?P<host>(?:(?P<subdomain>[\w\.]+)\.)?" . "(?P<domain>\w+\.(?P<extension>\w+)))";
$r = "!$r!";// Delimiters
preg_match($r, $a, $out);
// if you need only domain then return $out['domain'];
// if you need only host then return $out['host'];
// if you need only subdomain then return $out['subdomain'];
// if you need only extension then return $out['extension'];
// Full Data array
return $out;
}
$urls = array_map('getDomainname', $urls);
OR
function getsingaldomainHost($a)
{
$a = (substr($a, 0, 7) == "http://" || substr($a, 0, 8) == "https://") ? $a : 'http://' . $a;
$r = "/(?P<host>(?:(?P<subdomain>[a-z0-9][a-z0-9\-]{0,63}\.[a-z0-9]{0,62}))?(?P<domain>[a-z0-9][a-z0-9\-]{0,63}\.[a-z0-9]{0,62})(?P<extension>[a-z0-9][a-z0-9\-]{0,63}\.[a-z\.]{0,61}))$/i";
$pieces = parse_url($a);
if (isset($pieces['host'])) {
$domain = substr($pieces['host'], 0, 4) == "www." ? $pieces['host'] : 'www.' . $pieces['host'];
} else {
$domain = $pieces['path'];
}
if (preg_match($r, $domain, $regs)) {
return substr($regs['host'], 0, 4) == "www." ? substr($regs['host'], 4) : $regs['host'];
} else {
if ($rr == 1) {
return false;
} else {
return $a;
}
}
}
$urls = array_map('getsingaldomainHost', $urls);