1. 程式人生 > >get top level domain by php

get top level domain by php

else pos -- php top emp empty pty complete

function rLastParse($str, $sep, $cnt = 1, $complete_if_not = false)
{
$i = strrpos($str, $sep);
while (($cnt > 1) && ($i !== false)) {
$i = strrpos(substr($str, 0, $i), $sep);
$cnt--;
}
if ($i === false) {
return $complete_if_not ? $str : ‘‘;
}
else {
return substr($str, $i + strlen($sep));
}
}

function getTopLevelDomain()
{
if(isset($_SERVER[‘HTTP_X_FORWARDED_HOST‘]) && !empty($_SERVER[‘HTTP_X_FORWARDED_HOST‘])){
$host = $_SERVER[‘HTTP_X_FORWARDED_HOST‘];
}
else{
$host = $_SERVER[‘HTTP_HOST‘];
}
return rLastParse($host, DOT);
}

get top level domain by php