FeedParser
Library for parsing RSS/Atom feeds
Install / Use
/learn @alexdzyoba/FeedParserREADME
FeedParser
FeedParser is a PHP library that handles all types of XML feeds.
Example
(Also, in feed.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 titlegetDescription()- retrieve feed descriptiongetItems()- retrieve feed items as arraygetLink()- retrieve feed link (Link to feed website)getFeedLink()- retrieve feed link to itselfgetFeedType()- retrieve feed type as string
- Items
getTitle()- retrieve item titlegetContent()- retrieve item content as stringgetPubDate()- retrieve item publication date as PHP dategetLink()- 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 alex.dzyoba@gmail.com or ask through github.
Related Skills
node-connect
341.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
