Created
March 14, 2011 17:15
-
-
Save elidickinson/869473 to your computer and use it in GitHub Desktop.
Merge feeds in PHP with simplepie
This file contains 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 print '<?xml version="1.0" encoding="UTF-8"?>'; ?> | |
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> | |
<channel> | |
<title>FierceWireless</title> | |
<link>http://www.fiercewireless.com</link> | |
<description> | |
The latest wireless industry news from FierceWireless | |
</description> | |
<language>en-us</language> | |
<?php | |
// Include the SimplePie library | |
require_once('simplepie.inc'); | |
// Create a new SimplePie object | |
$feed = new SimplePie(); | |
$feed->cache = FALSE; | |
// Instead of only passing in one feed url, we'll pass in an array of three | |
$feed->set_feed_url(array( | |
'http://www.fiercewireless.com/feed?realfeed', | |
'http://www.fiercewireless.com/europe/feed', | |
)); | |
// Initialize the feed object | |
$feed->init(); | |
// This will work if all of the feeds accept the same settings. | |
$feed->handle_content_type(); | |
?> | |
<?php $itemcount = 0; ?> | |
<?php foreach($feed->get_items() as $item): ?> | |
<item> | |
<?php | |
foreach($item->data['child'][''] as $key => $value) { | |
//var_dump($value); | |
foreach($value as $idx => $data) { | |
print "<$key"; | |
$attribs = @$data['attribs']['']; | |
if($attribs) { | |
foreach($attribs as $attrib_name => $attrib_value) { | |
print " $attrib_name=\"" . htmlspecialchars($attrib_value) . "\""; | |
} | |
} | |
print ">"; | |
print htmlspecialchars($data['data']); | |
print "</$key>\n"; | |
} | |
} | |
?> | |
</item> | |
<?php if($itemcount++ > 30) { break; } ?> | |
<?php endforeach; ?> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment