This is documentation for Kohana v2.3.x. For v3.x documentation, see http://kohanaframework.org/guide .

Table of Contents
StatusDraft
TodoProof read

Feed Helper

The Feed helper assist in the parsing of remote RSS feeds.

Methods

parse()

parse($feed, $limit = 0) parses a remote feed and returns it as an array.

$feed = "feed.xml";
echo Kohana::debug(feed::parse($feed));

Use the code above on this RSS feed:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
<item>
	<title>Some feed item</title>
	<link>http://www.example.com/article34</link>
	<description>This article is really cool!</description>
	<author>Aart-Jan Boor</author>
	<pubDate>Sat, 08 Dec 2007 13:28:11 GMT</pubDate>
</item>
<item>
	<title>Some feed item2</title>
	<link>http://www.example.com/article546</link>
	<description>This article is really cool too!</description>
	<author>Aart-Jan Boor</author>
	<pubDate>Sat, 08 Dec 2007 12:57:56 GMT</pubDate>
</item>
<item>
	<title>Some feed item3</title>
	<link>http://www.example.com/article4523</link>
	<description>This article is the best!</description>
	<author>Aart-Jan Boor</author>
	<pubDate>Sat, 08 Dec 2007 12:39:42 GMT</pubDate>
</item>
</channel>
</rss>

It will result in HTML as:

Array
(
    [0] => Array
        (
            [title] => Some feed item
            [link] => http://www.example.com/article34
            [description] => This article is really cool!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 13:28:11 GMT
        )
 
    [1] => Array
        (
            [title] => Some feed item2
            [link] => http://www.example.com/article546
            [description] => This article is really cool too!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 12:57:56 GMT
        )
 
    [2] => Array
        (
            [title] => Some feed item3
            [link] => http://www.example.com/article4523
            [description] => This article is the best!
            [author] => Aart-Jan Boor
            [pubDate] => Sat, 08 Dec 2007 12:39:42 GMT
        )
 
)

create()

create($info, $items, $format = 'rss2') creates an xml feed from a collection of items.

$info = array('notes' => 'Foo bar');
$items = array(
    array(
        'title' => 'My very first feed created by KohanaPHP',
        'link' => 'http://www.example.com/article/34',
        'description' => 'This article is really nice!',
        'author' => 'Flip van Rijn',
        'pubDate' => 'Wed, 23 Sept 2009 17:13:25 GMT',
    ),
);
echo feed::create($info, $items);

That will result in this XML code:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
    <notes>Foo bar</notes>
    <title>Generated Feed</title>
    <link>http://localhost/</link>
    <generator>KohanaPHP</generator>
    <item>
        <title>My very first feed created by KohanaPHP</title>
        <link>http://www.example.com/article/34</link>
        <description>This article is really nice!</description>
        <author>Flip van Rijn</author>
        <pubDate>Wed, 23 Sept 2009 17:13:25 GMT</pubDate>
    </item>
</channel>
</rss>
helpers/feed.txt · Last modified: 2009/09/23 10:18 by intercoder