PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
then $domain will return "something.domain.com". I want it to return only "domain.com". I tried using strpos and substr to get rid of everything before the first dot but the subdomain part is not always present so that would be unreliable.
I would use parse_url() and then check if the host returned has more than one . - and if it does, explode the string using ".", unset the first part of the array returned, and implode the remaining 2 parts ('domain' and 'com')
Network functions? I am not sure I know what you are referring to exactly. Explode is relatively slow and the first element after http:// would be empty if no subdomain is given.
And how to solve problem with domains with two dots - e.g. domain.co.uk? I wanted to use only the last 2 array elements which would normally be domain & com but in this case it's not possible either.
here's how I've done this sort of thing in the past:
grabbed up the lists of TLDs throughout the world, compiled them into a list and created a pattern I can use in a regular expression. The domain is the first "word" to the left of the TLD.