2010-11-21 75 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'; 
    } 
} 
相關問題