CrazeD Posted March 23, 2008 Share Posted March 23, 2008 This is something I've been wanting/trying to do for quite a while now. It always intimidated me so I just didn't bother looking into it much. However this is something I need to add to my site now, so I need to learn how to do that. I've Googled it many times looking for tutorials and whatnot, and no solution so far has actually worked. I've tried pre-made scripts that all I had to do was add the URL, and they didn't work for me. So, I come here now and ask: what is the simplest way to parse an RSS feed to display the contents on my webpage? Will one script work for every RSS feed, or does it have to be fine-tuned to each different feed? Please don't tell me to just go search as I've already done that and can't find what I need. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/97465-how-to-parse-rss/ Share on other sites More sharing options...
Daniel0 Posted March 23, 2008 Share Posted March 23, 2008 Use SimpleXML. <?php $rss = new SimpleXMLElement('http://www.phpfreaks.com/forums/index.php?type=rss;action=.xml', null, true); echo "<ul>\n"; foreach ($rss->channel->item as $item) { echo "\t<li><a href='{$item->link}'>{$item->title}</a></li>\n"; } echo '</ul>'; ?> Output (currently): <ul> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188668.msg846635.html#msg846635'>Re: Backup Restore time-out</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188305.msg846634.html#msg846634'>Re: Different OO JavaScipt approaches: please advise</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188794.msg846633.html#msg846633'>Re: Updating some text every few seconds</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188734.msg846632.html#msg846632'>Re: Hooks?</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188798.msg846631.html#msg846631'>How to parse RSS...</a></li> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/97465-how-to-parse-rss/#findComment-498698 Share on other sites More sharing options...
CrazeD Posted March 28, 2008 Author Share Posted March 28, 2008 Is there any PHP4 alternatives? I found this but couldn't get it to work. It worked fine on with the example.xml that he made, but doesn't work with any URL's, I just get a blank page. Here is the code I'm accessing it with: <?php require ('xml_parse.php'); $xml = file_get_contents('http://www.phpfreaks.com/forums/index.php?type=rss;action=.xml'); $parser = new XMLParser($xml); $parser->Parse(); echo $parser->document->item[0]->title[0]->tagData; ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/97465-how-to-parse-rss/#findComment-502892 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.