Last two words with the delimiter "."

If the value of $myVar($_SERVER[“SERVER_NAME”]) is “dot.kr”,
I like to get the modified value of $myVar is “dot.kr

If the value of $myVar is “www.dot.kr”,
I like to get the modified value of $myVar is “dot.kr”

If the value of $myVar is “europe.dot.kr”,
I like to get the modified value of $myVar is “dot.kr

If the value of $myVar is “france/europe.dot.kr”,
I like to get the modified value of $myVar is “dot.kr

If the value of $myVar is “site.com”,
I like to get the modified value of $myVar is “site.com

If the value of $myVar is “www.site.com”,
I like to get the modified value of $myVar is “site.com

If the value of $myVar is “france/europe.site.com”,
I like to get the modified value of $myVar is “site.com

How can I modify $myVar for getting my target value(mainDomain) from each dynamic variable value(subDomain+mainDoamin) ?

(I like to get the main(registered) domain from the subDomains and mainDomains.)

<?php

$domains[] = 'dot.kr';
$domains[] = 'www.dot.kr';
$domains[] = 'france/europe.site.com';

foreach($domains as $domain){
	//This is where the modification starts
	$domain = explode('.', $domain);
	$domain_count = count($domain);
	if($domain_count >= 2) $domain = $domain[$domain_count-2].'.'.$domain[$domain_count-1];
	else $domain =  $domain[0];
	//This is where the modification ends
	echo $domain, '<br>';
}

I’ve exploded the variable on the ‘.’ character and just concatenated the last 2 parts back together. There might be a better way to do this, but that’s how I solved it.

Thank you very much, your code works fine.