Re: pulling data out of a string
| From: | Chris Lee | Date: | Tue, 15 May 2001 17:39:56 +0000 |
| Subject: | Re: pulling data out of a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-52915@lists.php.net to get a copy of this message | ||
this will remove the www plus the top level domain
<?php
$site = 'www.somesite.home.com';
$site = str_replace('www.', '', $site);
$site = explode('.', $site);
$site = array_pop($site);
$site = implode('.', $site);
// somesite.home
?>
this will remove the first host and the top level domain.
<?php
$site = 'www.somesite.home.com';
$site = explode('.', $site);
$site = array_pop($site);
$site = array_shift($site);
$site = implode('.', $site);
// somesite.home
?>
--
Chris Lee
lee@mediawaveonline.com
"Richard Kurth" <rkurth@pacifier.com> wrote in message news:126166105236.20010514143752@pacifier.com...
I am trying to figure out how to pull data out of a string. This is
driving me crazy. I figure an if statement of some sort would work but
I'm not sure how to structure it.
I know how to get what I want if it is just
$fullhostname = "www.domain.net";
$exp = explode(".", $fullhostname);
$host = $exp[0];
$domain = $exp[1];
$tld = $exp[2];
But what if it looks like this
$fullhostname = "www.mysit.dom.net";
I need
$host= www
$domain = mysit.dom
$tld = net
or this
$fullhostname = "mysite.domain.net";
$host =
$domain = mysite.domain
$tld = net
Or even worse this
$fullhostname = "mysit.dom.net";
$host =
$domain = mysit.dom
$tld = net
Best regards,
Richard
mailto:rkurth@pacifier.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net