Last active
August 29, 2015 14:24
-
-
Save JMichaelRoach/4edd8ec00584ad1defd9 to your computer and use it in GitHub Desktop.
PHP function to get domain name (not full host or server name)
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
| function get_domain_name() { | |
| $server_name = $_SERVER["SERVER_NAME"]; | |
| $domain_name = explode('.', $server_name); | |
| $i = count($domain_name) - 1; | |
| $domain_name = implode('.',array($domain_name[$i - 1],$domain_name[$i])); | |
| return $domain_name; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've seen a lot of fancy regular expressions versions of this, but this seems to work fine with little effort, and is much more readable.