2012-04-25 46 views
1

我正在尝试使用Simplepie为与正则表达式关键字过滤器匹配的项过滤饲料,然后使用这些项创建另一个饲料。不过,我无法将项目从$ matches数组移动到rss模块中。我仍然是PHP的新手,所以也许我错过了一些显而易见的东西,但是会很感激帮助。PHP来过滤/创建饲料

<?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; 
    } 
    } 
    ?> 

回答

0

您的$成功设置在某个地方吗? (你确实问过你是否错过了明显的东西!:D)

+0

就是这样 - 谢谢HC。 – user1357079 2012-04-25 23:46:00

0

您是否正确设置了标头,文档类型,所有类型的内容?您可能希望使用框架或XML/RSS编写器来构建响应,这比手动构建响应要容易得多。

+0

是的,我确定。我只是删除它们以节省空间。 – user1357079 2012-04-25 22:03:23