Hello Philip,

Monday, May 14, 2001, 3:36:17 PM, you wrote:

That my problem www is not always the host when it is a sub-domain it
would be like mysit.domain.net or sometimes people put a few extra
periods in the domain name like  www.my.test.net  I thought maybe I
could look at the string and find out how many periods are in it then
if there is a www before the first period if not treat it like a
sub-domain. The last period is is any thing after it would be the tld.
How would I count the periods

Philip Hallstrom> Is the host always going to be named "www"?  If it isn't then how can
Philip Hallstrom> you distinguish between www.domain.net and mysit.domain.net where in 
the
Philip Hallstrom> latter what you call the domain is "mysit.domain".  There's no way
Philip Hallstrom> around that one.  However, if you can assume that "www" is always the
Philip Hallstrom> name of the host then you could do something like this:


Philip Hallstrom> $fullhostname = "www.mysit.domain.net";
Philip Hallstrom> $exp = explode(".", $fullhostname);

Philip Hallstrom> if( $exp[0] == "www" )  {
Philip Hallstrom>         $hostname = array_shift($exp);
Philip Hallstrom> }else {
Philip Hallstrom>         $hostname = "";
Philip Hallstrom> }
Philip Hallstrom> $tld = array_pop($exp);
Philip Hallstrom> $domain = join(".", $exp);


Philip Hallstrom> That should do it...


Philip Hallstrom> In article <[EMAIL PROTECTED]> you write:
>>
>> 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:[EMAIL PROTECTED]
>>
>>
>>-- 
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>>





-- 
Best regards,
 Richard  
mailto:[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to