Skip to content

Instantly share code, notes, and snippets.

@unjadded
Forked from mburst/rss_reader.php
Last active August 29, 2015 14:19

Revisions

  1. @mburst mburst created this gist Mar 24, 2013.
    40 changes: 40 additions & 0 deletions rss_reader.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <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>