Last active
December 18, 2019 09:31
-
-
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
This file contains hidden or 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
| <?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>"; | |
| } | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example of output :
Alternative News
example of rsslinks.txt file content :