2

I have the following Simple XML Data:

  [Listeners] => 37
            [listener] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [IP] => 0.0.0.1
                            [UserAgent] => curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
                            [Connected] => 1236
                            [ID] => 120
                        )

                    [1] => SimpleXMLElement Object
                        (
                            [IP] => 0.0.0.2
                            [UserAgent] => curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
                            [Connected] => 1235
                            [ID] => 121
                        )

I want to show [IP].

So I have this PHP script:

<?php

$url = "http://admin:[email protected]/admin/listclients?mount=/FavoriteFM";
$xml = simplexml_load_file($url);
echo "<pre>";
print_r($xml);
 $IP = $xml->listener->IP;
 echo $IP[0];

?>

But it's not working. How can I display display IP in the proper way?

2
  • 1
    You should change your password on that service, it's now public. Commented Feb 7, 2015 at 0:26
  • Also if you didn't already saw it you can take a tour here: stackoverflow.com/tour and see how this site works! (There you also see how to edit your question; Welcome on SO) Commented Feb 7, 2015 at 0:34

3 Answers 3

1

Just change this line:

(You simply forgot the first level source)

$IP = $xml->listener->IP;

to this:

$IP = $xml->source->listener->IP;
        //^^^^^^^^ See here
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks. Now it just shows one IP. How to show ALL ip's?
@DennisdeWit Simply change: echo $IP[0]; -> print_r($IP); or you can use: foreach($IP as $v) echo $v . "<br />";
Can't we make a loop or so? Because I need them as a variable. I want to use $IP later to look up the country that comes with that IP.
@DennisdeWit The second example is a loop: foreach($IP as $v) echo $v . "<br />"; ?! Or what do you mean?
I still get to see only one IP-address. My goal is to make a script that can show ALL listeners. I want to put every IP into a variable. So later on, I can use that variable to look up the country where that IP comes from. So I want a geostat. Like: $IP = 0.0.0.0. --> API --> $location = Romania.
|
1

$url = "http://admin:[email protected]/admin/listclients?mount=/FavoriteFM";
$xml = simplexml_load_file($url);
$IP = $xml->source->listener;
    foreach($IP as $row){
      echo $row->IP;
    }

You will get all the IPs of array.

Comments

0

This should work for you:

foreach($xml->source->listener as $ip) 
    echo $ip->IP . "<br />"; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.