RE: Parse domain from URL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tijnema wrote:
> On 6/7/07, Brad Fuller <bfuller@xxxxxxxxxxxxxxxx> wrote:
>> 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
>>        )
>> 
>>    [snip]
>> )
>> Array
>> (
>> )
>> Array
>> (
>> )
>> */
>> 
>>> 
>> 
>> Any suggestions??
>> 
>> 
>> Thanks,
>> Brad
> 
> I have same results as you brad,
> I have Apache 2.2.3 + PHP 5.2.3RC1, so if you finally get it
> working, it's definitely not portable code :P Maybe it's an
> option to talk to a whois server?
> 
> Tijnema

Actually I need to get the root domain from the URL as a previous step to a
WHOIS query.  You can't do a WHOIS on "www.example.com".  It has to be
"example.com" only.

dig www.example.com  doesn't always give the information I need either.

I think DNS is the way to go, but need to figure out why dns_get_record()
returns an empty "authns" array for some of us but works properly for Robin
and for the example in the manual.  I haven't found anything yet, but I'll
keep searching.

Thanks,

Brad

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux