Previously, Richard Kurth said:
>
> 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

This is a little ugly, maybe, but it works:

<?php
    $hostname = 'www.myhost.test.com';

    $prefix = preg_replace( "/\..*$/",     "",  $hostname);
    $middle = preg_replace( "/^[^.]+\./",  "",  $hostname);
    $middle = preg_replace( "/\.[^.]+$/",  "",  $middle);
    $suffix = preg_replace( "/^.*\./",     "",  $hostname);

    print "prefix= $prefix<br>";
    print "suffix= $suffix<br>";
    print "middle= $middle<br>";
?>

Will output:

    prefix= www
    middle= myhost.test
    suffix= com

 -d

-- 
If God dropped acid, would he see people?  -George Carlin

-- 
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