woolyg Posted July 19, 2008 Share Posted July 19, 2008 Hi, Could someone maybe point out how I would do this? I'm trying to display the article:uid from the following XML string: <item> <title><![CDATA[Headline here]]></title> <link>http://www.ext_site.com/page/Headlines/0,,12306~1347132,00.html</link> <pubDate> Sat, 19 Jul 2008 10:50:00 +0100 </pubDate> <description><![CDATA[Description goes here]]></description> <article:uid>1347132</article:uid> </item> I'm using: <?php foreach ($xml->xpath('//item') as $item) { $title = $item->title; $description = $item->description; $guid = $item->xpath('//article:uid'); echo "<a href='$link'>".$guid." - ".$title."</a><br />".$description."<br />"; } ?> .. but the guid isn't displaying, it's only saying "Array" - can anyone help me on how to extract the 'article:uid' from the string? All help appreciated, Thanks - WoolyG Link to comment https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/ Share on other sites More sharing options...
MadTechie Posted July 20, 2008 Share Posted July 20, 2008 do a var_dump($guid); and post the results but as a guess try echo "<a href='$link'>".$guid[0]." - ".$title."</a><br />".$description."<br />"; Link to comment https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/#findComment-594512 Share on other sites More sharing options...
woolyg Posted July 20, 2008 Author Share Posted July 20, 2008 Hey, thanks for that. That works from one instance of <item>, but if I place more than one <item> instance into the XML, then the <article:uid> from the first <item> instance is echoed throughout the page, effectively giving: 1347132 - Headline here (Item 1) 1347132 - Second Headline (Item 2) .. and I'd like each UID to relate to the <item> it's contained inside.. do you get me? Thanks for your input thus far, any ideas? WoolyG Link to comment https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/#findComment-594516 Share on other sites More sharing options...
MadTechie Posted July 20, 2008 Share Posted July 20, 2008 try this.. <?php foreach ($xml->xpath('//item') as $K => $item) { $title = $item->title; $description = $item->description; $guid = $item->xpath('//article:uid'); echo "<a href='$link'>".$guid[$K]." - ".$title."</a><br />".$description."<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/#findComment-594519 Share on other sites More sharing options...
woolyg Posted July 20, 2008 Author Share Posted July 20, 2008 MadTechie, I bow before you. Works like a charm - thanks! WoolyG Link to comment https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/#findComment-594521 Share on other sites More sharing options...
MadTechie Posted July 20, 2008 Share Posted July 20, 2008 lol, your welcome can you click topic solved please Link to comment https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/#findComment-594523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.