简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM