Skip to content

Instantly share code, notes, and snippets.

@bdombro
Created April 18, 2014 17:12
Show Gist options
  • Save bdombro/11054640 to your computer and use it in GitHub Desktop.
Save bdombro/11054640 to your computer and use it in GitHub Desktop.
PHP RSS Feed
<?php
$rss = new DOMDocument();
$rss->load('http://www.newsfromota.com/category/ota-members/government-affairs-policy/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}
?>
<a target="_blank" href="http://www.newsfromota.com/category/ota-members/government-affairs-policy/">More...</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment