note 44709 added to function.explode
| From: | robertb at littlecutie dot net | Date: | Fri, 13 Aug 2004 22:30:53 +0000 |
| Subject: | note 44709 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74586@lists.php.net to get a copy of this message | ||
I've got several domains "parked" on one account, and I use this code in my index.php
to determine what domain I'm on. It lets me do a switch on the domain name without worrying
about whether the page was accessed as "www.domainname.com", "domainname.com",
or even "this.is.unusual.but.perfectly.legal.domainname.com". It works, though I wonder
whether it's the most efficient way to strip all but the last two tokens from the string.
<?php
$domain = strtolower($_SERVER['HTTP_HOST']);
// Break it up into pieces and only keep the last two
$domary = explode('.', $domain);
$parts = count($domary) - 2;
// Get rid of everything but the last two
for ($y=0; $y<$parts; $y++) {
unset($domary[$y]);
}
$domain = implode('.', $domary);
echo "Looks like you are on server $domain";
?>
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44709
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44709&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44709&report=yes
Search -- http://master.php.net/manage/user-notes.php