systomic26 Posted December 9, 2008 Share Posted December 9, 2008 Hey I was wandering if you guys could help me out with this. I'm kind of newbie so be patient please. It's supposed to take the first <item> from the specified rss feed and display it. <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $feed_url = "some feed url"; function getFeed($feed_url) { $content = file_get_contents($feed_url); $x = new SimpleXmlElement(channel->item as $entry); $children = $x->children(); $entry = $children[0]; echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a><br><br><p>" . $entry->description . "</p>"; } getFeed($feed_url); ?> Somebody please help. Link to comment https://forums.phpfreaks.com/topic/136258-help-with-this-script/ Share on other sites More sharing options...
rhodesa Posted December 9, 2008 Share Posted December 9, 2008 function getFeed($feed_url) { $content = file_get_contents($feed_url); $xml = new SimpleXmlElement($content); list($entry) = $xml->children(); printf('<a href="%s" title="%s">%s</a><br><br><p>%s</p>',$entry->link,$entry->title,$entry->title,$entry->description); } Link to comment https://forums.phpfreaks.com/topic/136258-help-with-this-script/#findComment-710783 Share on other sites More sharing options...
systomic26 Posted December 9, 2008 Author Share Posted December 9, 2008 function getFeed($feed_url) { $content = file_get_contents($feed_url); $xml = new SimpleXmlElement($content); list($entry) = $xml->children(); printf('<a href="%s" title="%s">%s</a><br><br><p>%s</p>',$entry->link,$entry->title,$entry->title,$entry->description); } That isn't working right. This script is not selecting the first <item> in the xml feed it is selective for the first <title>. This dispays the feed's name and description. I need it to display the first rss post on the list (the data found after the first <item> tag). I appreciate the suggestion though. Link to comment https://forums.phpfreaks.com/topic/136258-help-with-this-script/#findComment-710797 Share on other sites More sharing options...
rhodesa Posted December 9, 2008 Share Posted December 9, 2008 can you post the URL or contents of the feed? Link to comment https://forums.phpfreaks.com/topic/136258-help-with-this-script/#findComment-710835 Share on other sites More sharing options...
systomic26 Posted December 9, 2008 Author Share Posted December 9, 2008 The feed url is: http://www.scripting.com/rss.xml Link to comment https://forums.phpfreaks.com/topic/136258-help-with-this-script/#findComment-710836 Share on other sites More sharing options...
systomic26 Posted December 9, 2008 Author Share Posted December 9, 2008 I figured it out!! for anyone else that is interested here is the code: <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $feed_url = "some feed url"; function getFeed($feed_url) { $content = file_get_contents($feed_url); $xml = new SimpleXmlElement($content); $lis1 = (string) $xml->channel->item[0]->title; $lis2 = (string) $xml->channel->item[0]->description; $lis3 = (string) $xml->channel->item[0]->link; printf('<a href="%s" title="%s">%s</a><br><br><p>%s</p>',$lis3,$lis1,$lis1,$lis2); } getFeed($feed_url); ?> Thanks for helping me figure this out. Link to comment https://forums.phpfreaks.com/topic/136258-help-with-this-script/#findComment-710863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.