note 44709 deleted from function.explode by nlopess

From: Date: Fri, 13 Aug 2004 23:03:31 +0000
Subject: note 44709 deleted from function.explode by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74588@lists.php.net to get a copy of this message
Note Submitter: robertb@littlecutie.net ---- 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"; ?>

« previous php.notes (#74588) next »