note 106768 deleted from function.parse-url by tularis

From: Date: Mon, 05 Dec 2011 18:27:52 +0000
Subject: note 106768 deleted from function.parse-url by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184915@lists.php.net to get a copy of this message
Note Submitter: mark at shust dot com Reason: bad code ---- Here are a couple simple functions to get the root domain (example.com) from a full domain (sub.www.example.com) or url (http://www.example.com). <?php /** * Get root domain from full domain * @param string $domain */ public function getRootDomain($domain) { $domain = explode('.', $domain); $tld = array_pop($domain); $name = array_pop($domain); $domain = $name . $tld; return $domain; } /** * Get domain name from url * @param string $url */ public function getDomainFromUrl($url) { $domain = parse_url($url, PHP_URL_HOST); $domain = $this->getRootDomain($domain); return $domain; } ?>

« previous php.notes (#184915) next »