【问题标题】:rss flux filter simplepieRSS 通量过滤器 simplepie
【发布时间】:2012-10-06 17:11:53
【问题描述】:

我想使用 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 包含两个关键字,而不仅仅是一个或另一个。

【问题讨论】:

    标签: php rss simplepie feed


    【解决方案1】:

    已解决 这是解决方案:

    $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++;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多