Kemvkuritk
New Member
I've had a look round similar articles such as this one and I can't quite get it to work, quite possible I'm just misunderstanding.I've got a simple script which parses a bit of xml and prints out specific fields - what I'm having trouble doing is accessing the data of SimpleXMLElement Objects. XML (simplified for clarity)\[code\]<channel> <item> <title><![CDATA[Title is in here ...]]></title> <description>Our description is in here!</description> </item></channel>\[/code\]PHP\[code\]$url = "file.xml";$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);foreach ($xml->channel->item as $item) {$articles = array();$articles['title'] = $item->title;$articles['description'] = $item->description;}\[/code\]Up to this point, everything seems ok. I end up with an array of content which I can confirm with print_r, this is what I get back:\[code\]Array( [title] => SimpleXMLElement Object ( [0] => Title is in here ... ) [description] => SimpleXMLElement Object ( [0] => Our description is in here! ))\[/code\]The key questionHow do I then access [title][0] or [description][0]?I've tried a couple of variations with no success, most likely a rookie error somewhere!\[code\]foreach ($articles as $article) { echo $article->title; }\[/code\]and\[code\]foreach ($articles as $article) { echo $article['title'][0]; }\[/code\]and \[code\]foreach ($articles as $article) { echo $article['title']; }\[/code\]