I'm trying to use Simplepie to filter a feed for items that match a regex keyword filter, and then use those items to create another feed. However, I'm having trouble moving the items from the $matches array into the rss block. I'm still rather a novice with PHP, so maybe I'm missing something obvious, but would appreciate the help.
<?php
$feed = new SimplePie();
$feed->set_feed_url('feed://stackoverflow.com/feeds');
$feed->init();
$feed->set_cache_duration (3600);
$feed->set_timeout(30);
$feed->handle_content_type();
$countItem = 0;
foreach ($feed->get_items() as $item):
$checktitle = $item->get_title();
//Regex keyword filter
$pattern = '/php/i';
//If the there is a keyword match, store in $matches array
if (preg_match($pattern, $checktitle)) {
$matches[$countItem]= $item;
$countItem++;
}
endforeach
?>
<?php if ($success) {
$itemlimit=0;
foreach($matches as $item) {
if ($itemlimit==20) { break; }
?>
//rss block
<item>
<title><?php $item->get_title()); ?></title>
<link><?php echo $item->get_permalink(); ?></link>
<pubDate><?php echo $item->get_date();></pubDate>
<description><![CDATA[<?php echo $item->get_description(); ?>]]></description>
<content:encoded><![CDATA[<?php $item->get_content(); ?>]]></content:encoded>
</item>
<?
$itemlimit = $itemlimit + 1;
}
}
?>
Is your $success being set somewhere? (You did ask if you were missing something obvious! :D)