Code Monkey home page Code Monkey logo

codeigniter-rssparser's Introduction

RSSParser library - Production ready - CI 2.1.0 compatible

Install

Simply add this library to your /application/libraries/ folder.

Usage

If you have followed the Install step correctly you should be able to use.

$this->load->library('rssparser');							// load library
$this->rssparser->set_feed_url('http://example.com/feed'); 	// get feed
$this->rssparser->set_cache_life(30); 						// Set cache life time in minutes
$rss = $this->rssparser->getFeed(6); 						// Get six items from the feed

$rss will return an array which will include:

title, description, author, pubDate, link

You can also chain the above statement.

$this->load->library('rssparser');
$this->rssparser->set_feed_url('http://example.com/feed')->set_cache_life(30)->getFeed(6);

Example

Getting RSS from a single source.

function get_ars() 
{
	// Load RSS Parser
	$this->load->library('rssparser');
	
	// Get 6 items from arstechnica
	$rss = $this->rssparser->set_feed_url('http://feeds.arstechnica.com/arstechnica/index/')->set_cache_life(30)->getFeed(6);

	foreach ($rss as $item)
	{
		echo $item['title'];
		echo $item['description'];
	}
}

Getting RSS from multiple sources.

function get_logistics_news() 
{
	// Load RSS Parser
	$this->load->library('rssparser');
	
	// Get RSS
	$rss[] = $this->rssparser->set_feed_url('http://www.3plwire.com/feed/')->set_cache_life(30)->getFeed(1);
	$rss[] = $this->rssparser->set_feed_url('http://www.supplychain.cn/en/rss/articles/')->set_cache_life(30)->getFeed(1);

	foreach ($rss as $feed)
	{
		foreach ($feed as $item)
		{
			echo $item['title'];
			echo $item['description'];
		}
	}
}

Misc

// Using a callback function to parse addictional XML fields

$this->load->library('rssparser', array($this, 'parseFile')); // parseFile method of current class

function parseFile($data, $item)
{
	$data['summary'] = (string)$item->summary;
	return $data;
}

codeigniter-rssparser's People

Contributors

hasokeric avatar ollieza avatar stoney024 avatar tricki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.