Robin Vickery wrote:
> In that case you can't do it just by parsing alone, you need to use
> DNS. 
> 
> <?php
> function get_domain ($hostname) {
>   dns_get_record($hostname, DNS_A, $authns, $addt);   return
> $authns[0]['host']; }
> 
> print get_domain("www.google.com") . "\n"; print
> get_domain("google.com") . "\n"; print
> get_domain("www.google.co.uk") . "\n"; print
> get_domain("google.co.uk") . "\n"; print
> get_domain("google.co.uk") . "\n"; print
> get_domain("google.com.au") . "\n"; print
> get_domain("www.google.com.au") . "\n";
> 
> /* result
> google.com
> google.com
> google.co.uk
> google.co.uk
> google.co.uk
> google.com.au
> google.com.au
> */
>> 


Robin,

This is a very good solution, and I thank you for your response.  However I
had been experimenting with dns_get_record() before my original post and it
produces strange results on my machine.  And your example, on my machine,
produces no output.

<?
$dns_result = dns_get_record("www.google.com", DNS_A, $authns, $addt);

print_r($dns_result);
print_r($authns);
print_r($addt);

/* result
Array
(
    [0] => Array
        (
            [host] => www.l.google.com
            [type] => A
            [ip] => 64.233.161.99
            [class] => IN
            [ttl] => 136
        )

    [1] => Array
        (
            [host] => www.l.google.com
            [type] => A
            [ip] => 64.233.161.147
            [class] => IN
            [ttl] => 136
        )

    [2] => Array
        (
            [host] => www.l.google.com
            [type] => A
            [ip] => 64.233.161.103
            [class] => IN
            [ttl] => 136
        )

    [3] => Array
        (
            [host] => www.l.google.com
            [type] => A
            [ip] => 64.233.161.104
            [class] => IN
            [ttl] => 136
        )

)
Array
(
)
Array
(
)
*/

?>

Any suggestions??


Thanks,
Brad

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to