Running parse_url() on a string that may not contain the protocol
问题 I'm trying to get the domain name and TLD (no subdomain) from a user-input URL string which may or may not have protocol, directories, subdomains, filenames, etc. In other words, given any of the following: example.com www.example.com sub.example.com example.com/whatever/hey.html http://example.com https://subdomain.example.com ftp://example.com/whatever/hey.html I should always end up with: example.com . Right now this is what I am doing: $hostParts = explode('.', parse_url($URL, PHP_URL