2010-11-21 41 views
1

我想从给定的来源检索一些订阅源新闻,只有在特定的标签是这种情况下。Zend_Feed_Rss - 我可以回应,但我不能做任何事情吗?

我没有得到它,因为$ category不是一个字符串,因此strschr不会返回。 (所以我相信)。

function ultimasNoticiasBlog() 
    { 
     $channel = new Zend_Feed_Rss('http:/something.com/?feed=rss2'); 

     $news = array(); 

     foreach ($channel as $item) { 

      foreach ($item->category as $category) 
      { 
       //if any of the news has the tag "Sugestão" 
       if (strchr($category,'Sugestão')) 
       { 
        $news['find'] = "I have found a feed with your tag"; 
       } 
       else 
       { 
        echo 'Found Nothing'; 
       } 
      } 

      return $news; 
     } 
    } 

但是,如果我这样做: 回声$类别”我得到的所有类别印在视

我是什么没有得到这里请指点, MEM

更新:? 把它简单: 如果我做的: var_dump($category);我得到:

object(Zend_Feed_Element)#159 (3) { 
    ["_element:protected"]=> 
    object(DOMElement)#165 (0) { 
    } 
    ["_parentElement:protected"]=> 
    NULL 
    ["_appended:protected"]=> 
    bool(true) 
} 

object(Zend_Feed_Element)#156 (3) { 
    ["_element:protected"]=> 
    object(DOMElement)#166 (0) { 
    } 
    ["_parentElement:protected"]=> 
    NULL 
    ["_appended:protected"]=> 
    bool(true) 
} 

如果我这样做: echo $ category;

我得到的视口上: SugestaoAnotherTag1AnotherTag2 ...

我不明白为什么,更重要的是,我没有看到我怎么可以再看看“Sugestao不是这样或者” 。 :s

回答

0

尝试将其转换为字符串:(string)$category

1

我认为你正在寻找this page of the manual

foreach ($channel as $item) { 
    echo $item->title() . "\n"; 
} 

在你的情况,这应该工作(现在不能尝试,告诉我,如果它不工作,我会回来给你后来):

foreach ($channel as $item) { 
    //if any of the news has the tag "Sugestão" 
    if (strchr($item->category(),'Sugestão')){ 
    return "I have found a feed with your tag"; 
    }else { 
    return 'Found Nothing'; 
    } 
} 
相关问题