Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/97465-how-to-parse-rss/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/97465-how-to-parse-rss/#findComment-498698
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/97465-how-to-parse-rss/#findComment-502892
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.