Looks like a dup to me. The linked question contain answers that can solve your problem (and a bit more).
One of the answers uses
str_ireplace to make the following transformation:
http://www.google.com/ -> google.com
http://google.com/something/else -> google.com
http://www.abv.bg -> abv.bg
http://abv.bg -> abv.bg
which is similar to what you're asking, no?
P.S. consider using
preg_replace("/^www\./", "", $domain) instead of
str_ireplace to avoid inadvertently replacing too much e.g. for cases like "http://www.somewww.com/".
From your updates, I can just about guess what you're trying to achieve, i.e. truncate domain name to a single subdomain after the public suffix (effective TLD). I've given you a reopen vote but you'll have to do a lot better to convince others. Simply listing some examples with no explanation is hardly a question.
Had you spent as much effort on your question as you did fighting your case here and in the comments, you'd probably have gotten a sensible solution by now.
P.S. If I my second attempt at understanding your question is not too far off, then you might find this blog post useful. In short, regdom provide libraries in several languages (including PHP) that can do that for you.