systomic26 Posted December 9, 2008 Share Posted December 9, 2008 Hey all I got this script: $x = new SimpleXmlElement($content); foreach($x->channel->item as $entry) { echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; } This should take an rss xml feed and save the title with a link to the original post as $entry. The problem is that instead of the foreach() function I need a function or a different way to do this that will just take the first item on the list. Please help this is driving me nuts. Quote Link to comment Share on other sites More sharing options...
mrdamien Posted December 9, 2008 Share Posted December 9, 2008 <?php $x = new SimpleXmlElement($content); $children = $x->children(); $entry = $children[0]; // Child[0] is the first element. echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; ?> Quote Link to comment Share on other sites More sharing options...
systomic26 Posted December 9, 2008 Author Share Posted December 9, 2008 ok that worked kind of, when i run the script it displays the title of the rss feed. this is the first title xml tag. So I guess what I need is to get the second child, i guess. Is this possible? Quote Link to comment Share on other sites More sharing options...
systomic26 Posted December 9, 2008 Author Share Posted December 9, 2008 so I guess it can't be done then? Quote Link to comment Share on other sites More sharing options...
mrdamien Posted December 10, 2008 Share Posted December 10, 2008 If you mean the second child, then use: <?php $x = new SimpleXmlElement($content); $children = $x->children(); $entry = $children[1]; // Child[1] is the second element. echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; ?> If you mean the first sub-child of the first node, then use: <?php $x = new SimpleXmlElement($content); $level1 = $x->children(); $level2 = $level1->children(); $entry = $level2[0]; echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.