Skip to content

Instantly share code, notes, and snippets.

@MuhamadBaneshi
Forked from mburst/rss_reader.php
Created June 11, 2020 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuhamadBaneshi/91245eea272d959af9afef0ebb5a46db to your computer and use it in GitHub Desktop.
Save MuhamadBaneshi/91245eea272d959af9afef0ebb5a46db to your computer and use it in GitHub Desktop.
RSS Feed Reader in PHP
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment