note 24956 deleted from function.preg-match-all by sniper

From: Date: Tue, 30 Sep 2003 12:22:53 +0000
Subject: note 24956 deleted from function.preg-match-all by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57434@lists.php.net to get a copy of this message
Note Submitter: antony.booth@kill.webbots.com ---- The example to extract the domain from the URL is only good for a 2 part domain name (.company.com etc) but for 3 or more, it is not useful ( company.co.uk etc would return .co.uk). I found this more generic: - <?php //Get the web site address preg_match("/^(http:\/\/)?([^\/]+)/i", "http://www.multi.part.domain.name.com/index.html", $matches); $host = $matches[2]; // get all but one segments of host name preg_match_all("/\.([^\.\/]+)/",$host,$matches); // first element does not want the period('.') $matches[0][0] = $matches[1][0]; $domain = implode('',$matches[0]); echo( "Domain: " . $domain); ?> Displays: - Domain: multi.part.domain.name.com

« previous php.notes (#57434) next »