Created
March 24, 2013 03:58
-
-
Save mburst/5230448 to your computer and use it in GitHub Desktop.
RSS Feed Reader in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>RSS Feed Reader</title> | |
</head> | |
<body> | |
<?php | |
//Feed URLs | |
$feeds = array( | |
"http://maxburstein.com/rss", | |
"http://www.engadget.com/rss.xml", | |
"http://www.reddit.com/r/programming/.rss" | |
); | |
//Read each feed's items | |
$entries = array(); | |
foreach($feeds as $feed) { | |
$xml = simplexml_load_file($feed); | |
$entries = array_merge($entries, $xml->xpath("//item")); | |
} | |
//Sort feed entries by pubDate | |
usort($entries, function ($feed1, $feed2) { | |
return strtotime($feed2->pubDate) - strtotime($feed1->pubDate); | |
}); | |
?> | |
<ul><?php | |
//Print all the entries | |
foreach($entries as $entry){ | |
?> | |
<li><a href="<?= $entry->link ?>"><?= $entry->title ?></a> (<?= parse_url($entry->link)['host'] ?>) | |
<p><?= strftime('%m/%d/%Y %I:%M %p', strtotime($entry->pubDate)) ?></p> | |
<p><?= $entry->description ?></p></li> | |
<?php | |
} | |
?> | |
</ul> | |
</body> | |
</html> |
Good script. Works for a simple application
How can i take the data output and display it in my index.html page?
<?php
$NUMITEMS = 2;
$count = 0;
//Print all the entries
foreach($entries as $entry){
?>
<li><a href="<?= $entry->link ?>"><?= $entry->title ?></a> (<?= parse_url($entry->link)['host'] ?>)
<p><?= strftime('%m/%d/%Y %I:%M %p', strtotime($entry->pubDate)) ?></p>
<p><?= $entry->description ?></p></li>
<?php
}
if(++$count >= $NUMITEMS) break;
?>
<?php
$NUMITEMS = 2;
$count = 0;
//Print all the entries
foreach($entries as $entry){
?>
<li><a href="<?= $entry->link ?>"><?= $entry->title ?></a> (<?= parse_url($entry->link)['host'] ?>)
<p><?= strftime('%m/%d/%Y %I:%M %p', strtotime($entry->pubDate)) ?></p>
<p><?= $entry->description ?></p></li>
<?php
if(++$count >= $NUMITEMS) break;
}
?>
} <-- it must be befor the close php tag ?> else it would not count and break the foreach rule.
Can some help me with add a image with this code from the RSS Feed!
ahhhhh....... the best clean and simple rss reader
Nice. How i can get full text from an short rss link ?
Nice! Please how can I add feed media:thumbnail
I would recommend trying to var_dump($entry); in the last foreach loop as a means of debugging what is available on the $entry object
would you please write it again with load() function instead of simplexml_load_file()
simplexml_load_file() always make error
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to display max 5 items?