开发者

Zend_Feed_Rss - I can echo but I can't do anything else?

I would like to retrieve some feed news from a given feed source, only if a specific tag is the case.

I'm not getting it, because $category is not a string, hence strschr will not returned. (so I believe).

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

However, if I do: echo $category" I get all categories printed on the viewport.

What am I not getting here? Please advice, MEM

UPDATE: To put it simple: If I do: var_dump($category); I get:

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)
}

If I do: echo $category;

I get on the view port: SugestaoAnotherTag1AnotherTag2 ...

I'm not understanding why and, more important, I'm not seeing how can I then see if "Sugestao is the case or not". :s


I think you're looking for this page of the manual

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

In your case, this should work (can't try right now, tell me if it doesn't work, I'll come back to you later):

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


Try to cast it to string: (string)$category.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜