note 24958 added to function.preg-match
| From: | antony dot booth at kill dot webbots dot com | Date: | Thu, 05 Sep 2002 23:59:45 +0000 |
| Subject: | note 24958 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-36215@lists.php.net to get a copy of this message | ||
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
--
http://www.php.net/manual/en/function.preg-match.php
http://master.php.net/manage/user-notes.php?action=edit+24958
http://master.php.net/manage/user-notes.php?action=delete+24958
http://master.php.net/manage/user-notes.php?action=reject+24958