Zend_Feed_RSS Categories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Zend_Feed_RSS Categories

Post by onion2k »

I'm reading an RSS feed that contains elements like:

Code: Select all

<item>
<title>This is the title</title>
<link>http://link.com/</link>
<description>Description blah blah blah</description>
<category>Gardening</category>
<category>Plants</category>
<category>Flowers</category>
</item>
How do I access those categories? I've sort of figured it out using this:

Code: Select all

    $channel = new Zend_Feed_Rss("http://domain.com/rss");

    foreach ($channel as $item) {
        echo $item->title() . "<br />";
        echo $item->description() . "<br />";
        $categories = $item->category();
        foreach ($categories as $c) {
            echo $c->nodeValue;
        }
        echo "<br /><br />";
    }
That can't be right though, surely? That's completely abusing the DOM object nodes and accessing things I shouldn't be accessing publicly. I've looked through the documentation for Zend_Feed_Reader but the getCategories() method didn't seem to work for the RSS feed I'm consuming.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Zend_Feed_RSS Categories

Post by Christopher »

Have you dumped the feed object to see what it actually contains. It may only have the last category entry.
(#10850)
Post Reply