Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php rss通量过滤器simplepie_Php_Rss_Simplepie_Feed - Fatal编程技术网

Php rss通量过滤器simplepie

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-&

我想使用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->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++;
}
}