0

I want to make a filter for my rss news using simplepie. So I have this code:

$feed = new SimplePie();
$feed->set_feed_url(http://rss);
$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_permalink();
//Regex keyword filter
$pattern = '/keyword1|keyword2/';
//If the there is a keyword match, store in $matches array
if (preg_match($pattern, $checktitle)) {
    $news[$countItem]= $item;
    $countItem++;
}
}

I want $news to contain both keywords not just one or the other.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202

1 Answers1

0

Solved This is the solution :

$feed = new SimplePie();
$feed->set_feed_url(http://website.name/rss);
$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_permalink();
//Regex keyword filter
$pattern_one = '/keyword1/';
$pattern_two = '/keyword2/';
//If the there is a keyword match, store in $matches array
if (preg_match($pattern_one, $checktitle) && preg_match($pattern_two, $checktitle)) {
            $news[$countItem]= $item;
            $countItem++;
}
}