Giter Site home page Giter Site logo

feedparser's Introduction

FeedParser
==========

FeedParser is a PHP library that handles all types of XML feeds. 

Example
-------

(Also, in feed.php)

```php
<?php

// The only thing we need is include base class file
require_once('FeedParser.php');

// Get XML serialization of feed
$xml = file_get_contents($_POST['filename']);

// This is great. To work with feed we invoke only base class. All other work is 
// transparent.
$feed = new FeedParser($xml);

//Because we have interface for feeds, we invoke interface methods
echo '<b>Type:</b>'.$feed->getFeedType()."<br/>";
echo '<b>Title:</b>'.$feed->getTitle()."<br/>";
echo '<b>Description:</b>'.$feed->getDescription()."<br/>";
echo '<b>Feed link:</b>'.$feed->getFeedLink()."<br/>";
echo '<b>Link:</b>'.$feed->getLink()."<br/>";

$items = $feed->getItems();

// Stuff in your items can be empty, so you should somehow handle it.
// I've prepared is_empty function for you - enjoy.
$i=1;
foreach($items as $item)
{
	//Because we have interface for items, we invoke interface methods
	echo "<h1>";
	if(is_empty($item->getLink()))
		echo '<a href="#">';
	else
		echo '<a href="'.$item->getLink().'">';

	if(is_empty($item->getTitle()))
		echo "No title";
	else
		echo "$i. ".$item->getTitle();
	echo "</a>";

	echo "</h1>";

	if(is_empty($item->getPubDate()))
		echo "<i>"."No date"."</i><br/>";
	else
		echo "<i>".$item->getPubDate()."</i><br/>";

	if(is_empty($item->getContent()))
		echo "<i>"."No content"."</i><br/>";
	else
		echo $item->getContent()."<hr/>";

	$i++;
}

?>
```

Features and API
----------------

It supports:

 * RSS 0.90
 * RSS 1.0
 * RSS 1.1
 * RSS 0.91
 * RSS 0.92
 * RSS 2
 * Atom 1
 * Atom 0.3 (treated as Atom 1)

It has 2 interfaces - one for work with feeds, and the other one is to work with
feed's items.

Methods:

* Feeds
	- `getTitle()` - retrieve feed title
	- `getDescription()` - retrieve feed description
	- `getItems()` - retrieve feed items as array 
	- `getLink()` - retrieve feed link (Link to feed website)
	- `getFeedLink()` - retrieve feed link to itself
	- `getFeedType()` - retrieve feed type as string
* Items
	- `getTitle()` - retrieve item title
	- `getContent()` - retrieve item content as string
	- `getPubDate()` - retrieve item publication date as PHP date
	- `getLink()` - retrieve item link 


History
-------

I read a lot. I have about 100 RSS/Atom subscriptions, that i read every day.
It helps me to have actual knowledge and have fun. All feeds i read in google 
reader. However i didn’t like it much from the beginning because of small 
viewport. If you open google reader on small 1024×600 netbook screen you’ll 
understand what i’m talking about. For example, it’s really impossible to 
view photos.

That’s why i’ve decided to write my own reader and get practice in PHP/Yii.

So, if you want to read RSS/Atom, you have to parse it somehow. At first i 
wanted to use something already done and found XML_Feed_Parser library by 
James Stewart at PEAR. I’ve tried to fit it under my code, but despite all 
benefits, it wasn’t so “unified” as it was told in description. And 
that’s why I wrote my own library, based on James's work.

Source code distributed under terms of LGPLv3. 

If you have any questions, suggestions or anything else – write me email to 
[email protected] or ask through github.

feedparser's People

Contributors

mausvargas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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