Hi all
Can anyone explain where I'm going wrong here. I'm trying to read an xml feed. This is my code:
<?php
$completeurl =
'http://api.thingspeak.com/channels/5419/feed.xml';
//$xml = simplexml_load_file($completeurl);
$feed = file_get_contents($completeurl);
$xml = new SimpleXmlElement($feed);
foreach($xml->channel->feeds->feed as $item)
{
echo $item -> field1;
echo $item -> field2;
echo $item -> field3;
echo $item -> field4;
echo $item -> field5;
}
?>
The errors I'm getting are regarding the foreach line and are as follows:
- PHP Notice: Trying to get property of non-object
- PHP Warning: Invalid argument supplied for foreach()
I'm not sure what the problem is? The xml file structure can be viewed at the link