I want to echo the domain tld such as .com or .net from any domain
althought I want to echo if this domain https or http
example : https://facebook.com
I want to echo com and https
example 2 : http://blockchain.info
I want to echo info and http
example 3 :http://www.sub.test.info
I want to echo info and http
I have tried this
<?php
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
echo get_domain("https://facebook.com");
?>
but this echo facebook.com
edit: I want to echo domain tld and the https/http