1

特定のタグが該当する場合にのみ、特定のフィード ソースからフィード ニュースを取得したいと考えています。

$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 ...

理由がわかりません。さらに重要なことに、「スゲスタオがそうであるかどうか」を確認する方法がわかりません。:s

4

2 に答える 2

1

マニュアルのこのページを探していると思います

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';
  }
}
于 2010-11-23T10:58:40.267 に答える
0

それを string: にキャストしてみてください(string)$category

于 2010-11-23T10:46:37.803 に答える