Welcome Guest, Not a member yet? Register   Sign In
RSS parser library
#1

[eluser]Unknown[/eluser]
[h2]Introduction[/h2]
Simple lightweight library to parse RSS fields with caching

[h2]Instructions[/h2]
Just put attached file in your system/application/libraries folder and load this library into your application as usual. File source below

[h2]Example[/h2]
In your controller:
Code:
$this->load->library('Rss');

$this->rss->set_items_limit(2); // how many items to retreive from each feed
$this->rss->set_cache_life(10); // cache life in minutes
$this->rss->set_cache_path('/full/path/to/cache/dir/'); // by default library used CI default cache path, or path that you set in config.php
$this->rss->set_debug(); // in debug mode library will output on screen useful data

// parameter can be array or string
$this->rss->set_url(array('http://site.com/rss1.xml',
                     'http://site.com/rss2.xml'));
// return array of objects containing rss data from all feeds
$news = $this->rss->parse();

In your view
Code:
<?php if(isset($news) AND count($news) > 0):?>
    <?php foreach($news as $news_item):?>
        <div class="news">
            <h4>&lt;?php echo anchor($news_item->link, $news_item->title)?&gt;</h4>
            <p>
                &lt;?php if(isset($news_item->enclosure)):?&gt;
                    &lt;?php echo img($news_item->enclosure->attributes()->url)?&gt;
                &lt;?php endif;?&gt;
                &lt;?php echo $news_item->description?&gt;
            </p>
        </div>
    &lt;?php endforeach?&gt;
&lt;?php endif?&gt;

Also you can take a look at SimpleXMLElement PHP doc
#2

[eluser]Addow[/eluser]
Hi larikov,

Thanks for this excellent lightweight RSS library. I added an extra method to reset the url array and/or reset the settings when I am using the library in a single CI method or function.

I know you can add multiple url's at once, but I use the RSS library to parse sport rankings, provided in RSS (instead of XML) format.
#3

[eluser]Medikal[/eluser]
Hey man, love the simplistic lightweight libraries always! I was just curious, besides lightweight and currently being maintained, what are the advantages/disadvantages of this against a library like simplePie?
#4

[eluser]Unknown[/eluser]
Hello!

I was looking for an easy, straightforward way of adding a rss feed reader to my application - and I think this is what I need.

However, I don't seem to get it to work, I get this:

Quote:Message: Invalid argument supplied for foreach()
Filename: libraries/Rss.php
Line Number: 131

My controller:

Code:
$this->load->library('Rss');

        $this->rss->set_items_limit(1); // how many items to retreive from each feed
        $this->rss->set_cache_life(0); // cache life in minutes
        //$this->rss->set_cache_path('/full/path/to/cache/dir/'); // by default library used CI default cache path, or path that you set in config.php
        $this->rss->set_debug(false); // in debug mode library will output on screen useful data

        // parameter can be array or string
        $this->rss->set_url('http://www.dn.se/m/rss/senaste-nytt');

        // return array of objects containing rss data from all feeds
        $news = $this->rss->parse();

The feed I'm trying to retrieve is http://www.dn.se/m/rss/senaste-nytt.

I run PHP Version 5.3.2-1ubuntu4.7, and my CodeIgniter version is 1.7.2.

Any ideas, anyone?

regards,

Anders
#5

[eluser]Unknown[/eluser]
Please help.

I`m using:

$this->load->library('Rss');
$this->rss->set_items_limit(2);
$this->rss->set_cache_life(10);

$this->rss->set_debug(true);
$this->rss->set_url('...');
$news = $this->rss->parse();

I want to echo $news but I can`t understand the structure of it.
This is the raw RSS and the parse function returns an array for each item in channel.
So why can t I echo $news['2']?? or use foreach ($news as $item) echo $item['description']??

Code:
Raw RSS data:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 2.0
        )

    [channel] => SimpleXMLElement Object
        (
            [title] => Soccer Livescore by ScoresPro
            [description] => Soccer Livescore results in real time by ScoresPro
            [pubDate] => Mon, 25 Jul 2011 02:09:32 GMT
            [item] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [title] => Soccer Livescore: (MEX-AP) #Jaguares De Chiapas vs #Monterrey: 1-4
                            [description] => Game Finished
                            [pubDate] => Mon, 25 Jul 2011 00:58:31 GMT
                            [link] => scorespro
                        )

                    [1] => SimpleXMLElement Object
                        (
                            [title] => Soccer Livescore: (CAN-SL) #York Region Shooters vs #Toronto Croatia: 0-1
                            [description] => Game Finished
                            [pubDate] => Mon, 25 Jul 2011 00:01:31 GMT
                            [link] => scorespro
                        )

                    [2] => SimpleXMLElement Object
                        (
                            [title] => Soccer Livescore: (CAN-SL) #Brampton United vs #Brantford Galaxy: 4-0
                            [description] => Game Finished
                            [pubDate] => Sun, 24 Jul 2011 23:59:32 GMT
                            [link] => scorespro
                        )
                )
        )
)
#6

[eluser]Ninjabear[/eluser]
The file seems to be non existent or corrupted now, where can I get a copy from please?

I did find another RSSParser class but it didn't seem to support multiple feeds like this one.
#7

[eluser]Unknown[/eluser]
[quote author="Ninjabear" date="1334222040"]The file seems to be non existent or corrupted now, where can I get a copy from please?

I did find another RSSParser class but it didn't seem to support multiple feeds like this one.[/quote]

same problem here..
#8

[eluser]Unknown[/eluser]
hello every one hope u all are fine. i am not able to download rss.zip can any one help?
#9

[eluser]Unknown[/eluser]
how to download rss.zip?
#10

[eluser]umefarooq[/eluser]
hi guys you can find this library here

[url href="https://github.com/EllisLab/CodeIgniter/wiki/_pages"] CI wiki library download [/url]




Theme © iAndrew 2016 - Forum software by © MyBB