Don Freeman wrote:[color=blue]
> "Joe90" <boy_bandrejectREMOVE@hotmail.com> wrote in message
> news:d5e5mh$2ic$1@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
>[color=green]
>>I wish to only have 'domain.com' in a variable.
>>that would mean that all subdomains like:
>>whatever.domain.com
>>ftp.domain.com
>>mail.domain.com
>>
www.domain.com
>>supercalifragilisticexpialidocious.domain.com
>>domain.com
>>
>>would all except the last one be stripped of the hostname and my variable
>>would contain only
>>
>>DOMAIN.COM[/color]
>
>
> The best I could come up with is to break down your full name (like
> my.ftp.do.main.com, in the case "do.main.com" will be the actual domain)
> into separate elements using the "." as a delimiter. (see
>
http://us2.php.net/manual/en/function.explode.php on how to do this)
>
> Then taking the last two elements - domain & com (no sense testing on just
> the last as there are no domains named thusly) stringing them together with
> the "." separating them. Then test it using the checkdnsrr function
> (
http://us4.php.net/checkdnsrr) if it passes (won't in this case) then that
> is your actual domain, if not add the next (going right to left) element to
> the string with another "." as separator (now you would have do.main.com).
> Do another checkdnsrr, and so on (though in this case it would pass the
> test). This would be placed in a loop limited by the number of elements
> created.
> -Don Freeman
>[/color]
Good solution, except checkdnsrr() isn't implemented for Windows' PHP,
and it won't work for domains without a MX, or for valid subdomain
websites that do take their mail at the base domain. (eg.
www.johnsmith.domain.com could be a valid vhost who gets mail
@domain.com rather than @johnsmith.domain.com)