Last active
December 24, 2020 11:00
-
-
Save johnabela/86cf816184adfd6b99795b1a301654ea to your computer and use it in GitHub Desktop.
get domain name (without tld) from uri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = (substr($url, 0, 4) != 'http') ? 'http://'.$url : $url; | |
$url = preg_replace('~\.(com|info|net|io|us|org|me|co\.uk|ca|mobi)\b~i','',parse_url($url)['host']); | |
$url = substr($url,strrpos($url,'.')+1); | |
// examples: | |
// 'server.google.co.uk/abela'; // returns: google | |
// 'https://www.facebook.com/abela/'; // returns: facebook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment