-
-
Save nenoken/682bd79e2262cc6c85cca453322d4bff to your computer and use it in GitHub Desktop.
get domain name (without tld) from uri
This file contains hidden or 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