Created
June 21, 2016 07:10
-
-
Save SmugZombie/db9ed173dca1d0742392a54a85a0aee4 to your computer and use it in GitHub Desktop.
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
function getHost($Address) { | |
$parseUrl = parse_url(trim($Address)); | |
return trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2))); | |
} | |
getHost("example.com"); // Gives example.com | |
getHost("http://example.com"); // Gives example.com | |
getHost("www.example.com"); // Gives www.example.com | |
getHost("http://example.com/xyz"); // Gives example.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment