簡體   English   中英

Zend_Feed_Rss-我可以回聲,但是我無能為力?

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

我想從給定的提要源中檢索一些提要新聞,只有在使用特定標簽的情況下。

我不明白,因為$ 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;
      }
   }

但是,如果這樣做:echo $ category“,我將在視口上打印所有類別。

我什么不來? 請指教,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

我認為您正在尋找手冊的這一頁

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

嘗試將其轉換為string: (string)$category

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM