Jump to content

[SOLVED] Array displaying?


al

Recommended Posts

Dear PHP friends!

 

I'm trying to display DNS results Array retrived with PEAR Net_DNS Class line by line.

 

If I'm using only [authority] array section of results is easy to display it with foreach loop.

But I would like to display array [additional] address which is A record IP when it appears in the same line as [authority] section which is always present. Do I need to use some kind of double foreach or....?

 

Thank you for all your responses!

Al

 

 

<? php
// PEAR Net_DNS
require_once 'Net/DNS.php';
$dns = new Net_DNS_Resolver(array('nameservers' => array($dns_server)));

// Query DNS server
$response = $dns->rawQuery($domain);

// Loop Array 
if ($response) {

foreach ($response->authority as $result) {
echo "<tr bgcolor=white><td>" . $result->nsdname . "</td><td>" . $result->ttl . "</td></tr>";
            }
}

?>

 

 

 

Array results:

Net_DNS_Packet Object
(
    [debug] => 0
    [header] => Net_DNS_Header Object
        (
            [id] => 52392
            [qr] => 1
            [opcode] => QUERY
            [aa] => 0
            [tc] => 0
            [rd] => 1
            [ra] => 0
            [rcode] => NOERROR
            [qdcount] => 1
            [ancount] => 0
            [nscount] => 4
            [arcount] => 4
        )

    [compnames] => Array
        (
        )

    [answerfrom] => l.gtld-servers.net
    [answersize] => 164
    [question] => Array
        (
            [0] => Net_DNS_Question Object
                (
                    [qname] => google.com
                    [qtype] => A
                    [qclass] => IN
                )

        )

    [answer] => Array
        (
        )

    [authority] => Array
        (
            [0] => Net_DNS_RR_NS Object
                (
                    [name] => google.com
                    [type] => NS
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 6
                    [rdata] => ns1�
                    [nsdname] => ns1.google.com
                )

            [1] => Net_DNS_RR_NS Object
                (
                    [name] => google.com
                    [type] => NS
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 6
                    [rdata] => ns2�
                    [nsdname] => ns2.google.com
                )

            [2] => Net_DNS_RR_NS Object
                (
                    [name] => google.com
                    [type] => NS
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 6
                    [rdata] => ns3�
                    [nsdname] => ns3.google.com
                )

            [3] => Net_DNS_RR_NS Object
                (
                    [name] => google.com
                    [type] => NS
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 6
                    [rdata] => ns4�
                    [nsdname] => ns4.google.com
                )

        )

    [additional] => Array
        (
            [0] => Net_DNS_RR_A Object
                (
                    [name] => ns1.google.com
                    [type] => A
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 4
                    [rdata] => �� 

                    [address] => 216.239.32.10
                )

            [1] => Net_DNS_RR_A Object
                (
                    [name] => ns2.google.com
                    [type] => A
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 4
                    [rdata] => ��"

                    [address] => 216.239.34.10
                )

            [2] => Net_DNS_RR_A Object
                (
                    [name] => ns3.google.com
                    [type] => A
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 4
                    [rdata] => ��$

                    [address] => 216.239.36.10
                )

            [3] => Net_DNS_RR_A Object
                (
                    [name] => ns4.google.com
                    [type] => A
                    [class] => IN
                    [ttl] => 172800
                    [rdlength] => 4
                    [rdata] => ��&

                    [address] => 216.239.38.10
                )

        )

)

 

Link to comment
https://forums.phpfreaks.com/topic/179188-solved-array-displaying/
Share on other sites

it would seem all you need to do is add a key to your foreach() assignment, and use that key to access the equivalent entry in the additional array:

 

foreach ($response->authority as $k => $result)
{
  echo "authority is {$result->nsdname}, additional is {$response->additional[$k]->nsdname}";
}

 

i don't know if that object notation will work, but the principle remains the same (using the key in the foreach to access the matching object in the additional array).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.