rss:combine_multiple_rss_feeds
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rss:combine_multiple_rss_feeds [2016/10/09 14:31] – peter | rss:combine_multiple_rss_feeds [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 169: | Line 169: | ||
< | < | ||
<?php endforeach; ?> | <?php endforeach; ?> | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Another Way ===== | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | // Set the feed URLs here | ||
+ | $feeds = array( | ||
+ | //' | ||
+ | //' | ||
+ | |||
+ | ' | ||
+ | ' | ||
+ | // etc. | ||
+ | ); | ||
+ | |||
+ | |||
+ | // Get all feed entries | ||
+ | $entries = array(); | ||
+ | foreach ($feeds as $feed) { | ||
+ | $xml = simplexml_load_file($feed); | ||
+ | $entries = array_merge($entries, | ||
+ | } | ||
+ | |||
+ | // Sort feed entries by pubDate (ascending) | ||
+ | usort($entries, | ||
+ | //return strtotime($x-> | ||
+ | return strtotime($y-> | ||
+ | }); | ||
+ | |||
+ | print_r($entries); | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Another way ===== | ||
+ | |||
+ | With 4 lines, I import a rss to an array. | ||
+ | |||
+ | <code php> | ||
+ | $feed = implode(file(' | ||
+ | $xml = simplexml_load_string($feed); | ||
+ | $json = json_encode($xml); | ||
+ | $array = json_decode($json, | ||
+ | </ | ||
+ | |||
+ | Try also changing 1st line for one of these... | ||
+ | |||
+ | <code php> | ||
+ | $feed = file_get_contents(' | ||
+ | $feed = json_decode(json_encode(simplexml_load_file(' | ||
+ | </ | ||
+ | |||
+ | |||
+ | For a more complex solution | ||
+ | |||
+ | <code php> | ||
+ | $feed = new DOMDocument(); | ||
+ | | ||
+ | $json = array(); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | $i = 0; | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | $guid = $item-> | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | echo json_encode($json); | ||
</ | </ |
rss/combine_multiple_rss_feeds.1476023488.txt.gz · Last modified: 2020/07/15 09:30 (external edit)