php_PHP チュートリアルで URL のルート ドメイン名を取得するコード

WBOY
リリース: 2016-07-21 15:31:33
オリジナル
899 人が閲覧しました

复制代码代码如下:

/**
* ルートドメイン名を取得します
*
* @author 寂しい
* @create 2011-3-11
* @version 0.1
* @lastupdate 寂しい
* @package Sl
*/
class Sl_RootDomain{
static $self;
プライベート $ドメイン=null;
プライベート $host=null;
プライベート$state_domain;
プライベート $top_domain;
/**
* ドメイン名分析の例を取得します
* ここに説明を入力してください ...
*/
パブリック静的関数 instace(){
if(!self::$self)
self::$self=new self();
self::$self を返します。
}
プライベート関数 __construct(){
$this->state_domain=array(
'al','dz','af','ar','ae','aw','om','az ','eg','et','ie','ee','ad','ao','ai','ag','at','au','mo','bb', 'pg','bs','pk','py','ps','bh','pa','br','by','bm','bg','mp','bj ','be','is','pr','ba','pl','bo','bz','bw','bt','bf','bi','bv', 'kp','gq','dk','de','tl','tp','tg','dm','do','ru','ec','er','fr ','fo','pf','gf','tf','va','ph','fj','fi','cv','fk','gm','cg', 'cd','co','cr','gg','gd','gl','ge','cu','gp','gu','gy','kz','ht ','kr','nl','an','hm','hn','ki','dj','kg','gn','gw','ca','gh', 'ga','kh','cz','zw','cm','qa','ky','km','ci','kw','cc','hr','ke ','ck','lv','ls','la','lb','lt','lr','ly','li','re','lu','rw', 'ro'、'mg'、'im'、'mv'、'mt'、'mw'、'my'、'ml'、'mk'、'mh'、'mq'、'yt'、'mu ','mr','us','um','as','vi','mn','ms','bd','pe','fm','mm','md', 'ma'、'mc'、'mz'、'mx'、'nr'、'np'、'ni'、'ne'、'ng'、'nu'、'no'、'nf'、'na ','za','aq','gs','eu','pw','pn','pt','jp','se','ch','sv','ws', 'yu'、'sl'、'sn'、'cy'、'sc'、'sa'、'cx'、'st'、'sh'、'kn'、'lc'、'sm'、'pm ','vc','lk','sk','si','sj','sz','sd','sr','sb','so','tj','tw', 'th'、'tz'、'to'、'tc'、'tt'、'tn'、'tv'、'tr'、'tm'、'tk'、'wf'、'vu'、'gt ','ve','bn','ug','ua','uy','uz','es','eh','gr','hk','sg','nc', 'nz','hu','sy','jm','am','ac','ye','iq','ir','il','it','in','id ','uk','vg','io','jo','vn','zm','je','td','gi','cl','cf','cn', 「年」
);
$this->top_domain=array('com','arpa','edu','gov','int','mil','net','org','biz','info', 'pro','name','museum','coop','aero','xxx','idv','me','mobi');
$this->url=$_SERVER['HTTP_HOST'];
}
/**
* 設置URL
* ここに説明を入力してください ...
* @param string $url
*/
public function setUrl($url=null){
$url=$url?$url:$this->url;
if(empty($url))$this を返す;
if(!preg_match("/^http::/is", $url))
$url="http://".$url;
$url=parse_url(strto lower($url));
$urlarr=explode(".", $url['host']);
$count=カウント($urlar);
if ($count$this->domain=array_pop($url);
}else if ($count>2){
$last=array_pop($urlarr);
$last_1=array_pop($urlar);
if(in_array($last, $this->top_domain)){
$this->domain=$last_1.'.'.$last;
$this->host=implode('.', $urlarr);
}else if (in_array($last, $this->state_domain)){
$last_2=array_pop($urlar);
if(in_array($last_1, $this->top_domain)){
$this->domain=$last_2.'.'.$last_1.'.'.$last;
$this->host=implode('.', $urlarr);
}else{
$this->host=implode('.', $urlarr).$last_2;
$this->domain=$last_1.'.'.$last;
}
}
}
$this を返す;
}
/**
* ドメイン名を取得します
* ここに説明を入力します ...
*/
public function getDomain(){
return $this->domain;
}
/**
* ホストを取得
* ここに説明を入力してください ...
*/
public function getHost(){
return $this->host;
}
}
?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/3230.mlテクノロジーアドレス: ?php /*** ルート ドメイン名を取得します * * @authorlonely * @create 2011-3-11 * @version 0.1 * @lastupdatelonely * @package Sl*/ class Sl_RootDomain{ プライベートステータス...
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!