PHP获取顶级域名
<?php
header("Content-type:text/html;charset=gb2312");
function getdomain($url) {
$host = strtolower ( $url );
if (strpos ( $host, '/' ) !== false) {
$parse = @parse_url ( $host );
$host = $parse ['host'];
}
$topleveldomaindb = array ('com', 'edu', 'gov', 'int', 'mil', 'net', 'org', 'biz', 'info', 'pro', 'name', 'museum', 'coop', 'aero', 'xxx', 'idv', 'mobi', 'cc', 'me' );
$str = '';
foreach ( $topleveldomaindb as $v ) {
$str .= ($str ? '|' : '') . $v;
}
$matchstr = "[^\.]+\.(?:(" . $str . ")|\w{2}|((" . $str . ")\.\w{2}))$";
if (preg_match ( "/" . $matchstr . "/ies", $host, $matchs )) {
$domain = $matchs ['0'];
} else {
$domain = $host;
}
return $domain;
}
$str = $_SERVER['HTTP_HOST'];
$su = getdomain ( $str );
if($su == 'badcatxt.com'){
echo "BadCat读书网";
}else{
echo "BadCat";
}
?>
织梦获取顶级域名
{dede:geturl runphp='yes'}
function getdomain($url) {
$host = strtolower ( $url );
if (strpos ( $host, '/' ) !== false) {
$parse = @parse_url ( $host );
$host = $parse ['host'];
}
$topleveldomaindb = array ('com', 'edu', 'gov', 'int', 'mil', 'net', 'org', 'biz', 'info', 'pro', 'name', 'museum', 'coop', 'aero', 'xxx', 'idv', 'mobi', 'cc', 'me' );
$str = '';
foreach ( $topleveldomaindb as $v ) {
$str .= ($str ? '|' : '') . $v;
}
$matchstr = "[^\.]+\.(?:(" . $str . ")|\w{2}|((" . $str . ")\.\w{2}))$";
if (preg_match ( "/" . $matchstr . "/ies", $host, $matchs )) {
$domain = $matchs ['0'];
} else {
$domain = $host;
}
return $domain;
}
$str = $_SERVER['HTTP_HOST'];
$su = getdomain ( $str );
if( $su == 'badcatxt.com' ){
@me = "BadCat读书网";
}
else{
@me = "Badcat";
}
{/dede:geturl}