Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Created June 21, 2016 07:10
Show Gist options
  • Save SmugZombie/db9ed173dca1d0742392a54a85a0aee4 to your computer and use it in GitHub Desktop.
Save SmugZombie/db9ed173dca1d0742392a54a85a0aee4 to your computer and use it in GitHub Desktop.
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