Skip to content

Instantly share code, notes, and snippets.

@johnabela
Last active December 24, 2020 11:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnabela/86cf816184adfd6b99795b1a301654ea to your computer and use it in GitHub Desktop.
Save johnabela/86cf816184adfd6b99795b1a301654ea to your computer and use it in GitHub Desktop.
get domain name (without tld) from uri
$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