note 24958 deleted from function.preg-match by sniper

From: Date: Tue, 30 Sep 2003 12:13:41 +0000
Subject: note 24958 deleted from function.preg-match by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57394@lists.php.net to get a copy of this message
Note Submitter: antony.booth@kill.webbots.com ---- The Domain name example would work only for a 2 part domain name. The example below works for a domain of any length: - <?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 (#57394) next »