Friday, 6 February 2015

How to XML to PHP?



I have the following Simple XML Data:



SimpleXMLElement Object
(
[source] => SimpleXMLElement Object
(
[@attributes] => Array
(
[mount] => /FavoriteFM
)

[Listeners] => 38
[listener] => Array
(
[0] => SimpleXMLElement Object
(
[IP] => 0.0.0.0
[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] => 201471
[ID] => 2972275
)


I want to show [IP].


So I have this PHP script:



<?php

$url = "http://ift.tt/1IkJkvH";
$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?


No comments:

Post a Comment