Skip to content

Instantly share code, notes, and snippets.

@reuniware
Last active December 18, 2019 09:31
Show Gist options
  • Select an option

  • Save reuniware/d08efad0a6e45df87ad807a3cc318894 to your computer and use it in GitHub Desktop.

Select an option

Save reuniware/d08efad0a6e45df87ad807a3cc318894 to your computer and use it in GitHub Desktop.
PHP : Get Rss Feed from multiple sources (rss links in rsslinks.txt file) and show them on one file
<?php
if (isset($_GET['feedid'])){
}
$filename = "rssfeeds.txt";
//$lines = file($filename, FILE_IGNORE_NEW_LINES);
$arr = file("rsslinks.txt", FILE_IGNORE_NEW_LINES);
/*$arr = array(
"https://news.un.org/feed/subscribe/en/news/region/middle-east/feed/rss.xml",
"https://news.un.org/feed/subscribe/en/news/region/europe/feed/rss.xml",
);*/
foreach ($arr as &$value) {
try {
getFeed($value);
}catch(exception $e){
echo "$e";
}
}
exit;
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
foreach($x->channel as $entry) {
echo "<h3>$entry->title ";
if ($entry->lastBuildDate<>"") echo "($entry->lastBuildDate)";
echo "</h3>";
}
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "<li>$entry->pubDate : <a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
if ($entry->description <> "") {
echo "$entry->description";
echo "<br/><br/>";
} else {
}
}
echo "</ul>";
}
?>