PHP str_replace(all Text Before A dot & all Text After that dot

Hi Guys,
Using PHP str_replace I'm trying to break down a domain name (ANYdomain1.ANYdomain2) into its parts,
so that I can get this result:

I also want to delete the "." (dot) between ANYdomain1.ANYdomain2.
I can't find my solution on the web, but I think this is an easy one for the experts.
Thanks in advance,
Who is Participating?
Ray PaseurConnect With a Mentor Commented: will do it.  Use the dot as the string separator.
Ray PaseurCommented:
That said, you might want to think carefully about your test data.  For example, consider these two URLs: and  What is the exact output you would want from each of those?
sasnaktivAuthor Commented:
Thanks Ray,
I can always address the "www." by starting with this:

$http_host = str_replace('http://www.', '' , $_SERVER['HTTP_HOST']);
$http_host=str_replace('www.', '',$http_host);

Then following with the EXPLODE you suggested.

Thanks again,
Ray PaseurCommented:
Thanks for the points - just be careful about the structure you expect to get from URLs.  There are things like that may produce "interesting" results.

Best regards, ~Ray
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.