php和织梦获取顶级域名 ,根据判断输出指定文字

来源:互联网 发布:手机怎样开淘宝店 编辑:程序博客网 时间:2024/06/05 00:09

PHP获取顶级域名

<?phpheader("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}
0 0
原创粉丝点击