Php rss通量过滤器simplepie
我想使用simplepie为我的rss新闻制作一个过滤器。 所以我有这个代码:Php rss通量过滤器simplepie,php,rss,simplepie,feed,Php,Rss,Simplepie,Feed,我想使用simplepie为我的rss新闻制作一个过滤器。 所以我有这个代码: $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-&
$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++;
}
}
我希望$news同时包含两个关键字,而不是一个或另一个。已解决这是解决方案:
$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++;
}
}