PHPackages                             benkle/feed-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. benkle/feed-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

benkle/feed-parser
==================

Rule-based RSS and Atom parser

2.1.0(8y ago)020MITPHPPHP &gt;=5.6.0

Since May 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/benkle-libs/feed-parser)[ Packagist](https://packagist.org/packages/benkle/feed-parser)[ RSS](/packages/benkle-feed-parser/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

A rule-based RSS and Atom parser
================================

[](#a-rule-based-rss-and-atom-parser)

This PHP library contains an extensible, rule based parser for RSS and Atom news feeds. It's way of working is inpsired by [Alex Debril's feed-io](https://packagist.org/packages/debril/feed-io), but it's been rewritten from scratch to be a bit cleaner and more easily extensible. It doesn't have all the features of the original, but you can easily create new parsing standards or extend existing one without rummaging through the library code.

Requirements
------------

[](#requirements)

- PHP 5.6+
- [masterminds/html5](https://packagist.org/packages/masterminds/html5) 2.2+
- [psr/log](https://packagist.org/packages/psr/log) 1.0+

Installation
------------

[](#installation)

*FeedParser* can be included in the usual way with composer:

```
    composer require benkle/feed-parser
```

Usage
-----

[](#usage)

For a quick start you can instantiate the class `\Benkle\FeedParser\Reader` and directly fetch a feed:

```
$reader = new \Benkle\FeedParser\Reader();
$feed = $reader->read(file_get_contents('http://xkcd.com/atom.xml'));

echo $feed->getTitle() . PHP_EOL;
foreach ($feed->getItems() as $item) {
    echo "\t" . $item->getTitle() . PHP_EOL;
}
```

### Create your own rules

[](#create-your-own-rules)

*FeedParser* is based on rules, which are organized on standards.

A rule can be any class implementing `\Benkle\FeedParser\Interfaces\RuleInterface`:

```
class MyRule implements \Benkle\FeedParser\Interfaces\RuleInterface {
    public function canHandle(\DOMNode $node, \Benkle\FeedParser\Interfaces\NodeInterface $target)
    {
        return $node->nodeName == 'title' && $target instanceof \Benkle\FeedParser\Interfaces\ChannelInterface;
    }

    public function handle(\Benkle\FeedParser\Parser $parser, \DOMNode $node, \Benkle\FeedParser\Interfaces\NodeInterface $target)
    {
        /** \Benkle\FeedParser\Interfaces\ChannelInterface $target */
        $target->setTitle($node->nodeValue);
    }
}
```

Rules can be added to any standard via it's rule set, which is a priority ordered list:

```
/** @var \Benkle\FeedParser\Interfaces\StandardInterface $standard */
foreach ($reader->getStandards() as $standard) {
    $standard->getRules()->add(new MyRule(), 5); // Rules are ordered by priority
}
```

But often you might want to aggregate all your rules in a standard. Standards are classes implementing `\Benkle\FeedParser\Interfaces\StandardInterface`:

```
class MyStandard implements \Benkle\FeedParser\Interfaces\StandardInterface {
    use \Benkle\FeedParser\Traits\WithParserTrait;
    use \Benkle\FeedParser\Traits\WithRuleSetTrait;

    public function __construct()
    {
        $this->getRules()->add(new MyRule(), 5);
    }

    public function newFeed()
    {
        return new \Benkle\FeedParser\Feed();
    }

    public function getRootNode(\DOMDocument $dom)
    {
        return $dom->getElementsByTagName('feed')->item(0);
    }

    public function canHandle(\DOMDocument $dom)
    {
        return $dom->getElementsByTagName('feed')->length > 0;
    }
}
```

Adding a standard to a Reader is just as simple as adding a rule to a standard:

```
$reader->getStandards()->add(new MyStandard(), 5);
```

Included standards are:

- `Atom10Standard` for Atom 1.0
- `RSS09Standard` for RSS 0.9
- `RSS10Standard` for RSS 1.0
- `RSS20Standard` for RSS 2.0

### Set your own DOM parser

[](#set-your-own-dom-parser)

This library uses the PHP DOM library classes for it's XML traversing. To use your own library you have to write a wrapper arround it implementing `\Benkle\FeedParser\Interfaces\DOMParserInterface`:

```
$reader->setDomParser(new class implements \Benkle\FeedParser\Interfaces\DOMParserInterface {
    public function parse($source)
    {
        $parser = new \MyFancy\DomParser();
        return $parser->parse($source);
    }
});
```

*FeedParser* already include a wrapper for the standard library, which is fast but fails when a feeds isn't valid XML, and for the [Masterminds HTML5 parser](https://packagist.org/packages/masterminds/html5), which is more fault tolerant, but also way slower. It also includes a meta wrapper which will try any number of other wrappers it is given, allowing you to balance speed and reliability:

```
$reader->setDomParser(
    new \Benkle\FeedParser\DOMParsers\FallbackStackParser(
        new \Benkle\FeedParser\DOMParsers\PHPDOMParser(),
        new \Benkle\FeedParser\DOMParsers\MastermindsHTML5Parser()
    )
);
```

**Note:** This Wrapper implements `Psr\Log\LoggerAwareInterface` and will write notices whenever any of it's protegé throws an exception!

### More control

[](#more-control)

If you need more control over what standards are loaded, and don't need file and http access, you can use the `\Benkle\FeedParser\BareReader` class:

```
$reader = new \Benkle\FeedParser\BareReader();
$reader->setDomParser(new \Benkle\FeedParser\DOMParsers\PHPDOMParser());
$reader->getStandards()->add(new \Benkle\FeedParser\Standards\RSS\RSS20Standard());
```

TODO
----

[](#todo)

- Moved included class `PriorityList` to a utility package.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~94 days

Recently: every ~113 days

Total

6

Last Release

3166d ago

Major Versions

1.2.0 → 2.0.02017-04-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/70253fd266a8069896d4d0265ba3d452d6e4a006cbf564a11bfaf692ca5bb44c?d=identicon)[bizzl-greekdog](/maintainers/bizzl-greekdog)

---

Top Contributors

[![bizzl-greekdog](https://avatars.githubusercontent.com/u/424349?v=4)](https://github.com/bizzl-greekdog "bizzl-greekdog (51 commits)")

---

Tags

parseratomfeedrssRDF

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/benkle-feed-parser/health.svg)

```
[![Health](https://phpackages.com/badges/benkle-feed-parser/health.svg)](https://phpackages.com/packages/benkle-feed-parser)
```

###  Alternatives

[simplepie/simplepie

A simple Atom/RSS parsing library for PHP

1.6k8.7M69](/packages/simplepie-simplepie)[yuzuru-s/parse-rss

This PHP library can easily parse xml files, especially RSS1.0, RSS2.0 and ATOM.

1038.7k](/packages/yuzuru-s-parse-rss)[bnomei/kirby3-feed

Generate a Atom/JSON/RSS-Feed and XML-Sitemap from Pages-Collections

7224.8k](/packages/bnomei-kirby3-feed)[phanan/poddle

Parse podcast feeds with PHP following PSP-1 Podcast RSS Standard

1721.4k1](/packages/phanan-poddle)[php-feed-io/feed-io

PHP library built to consume and serve JSONFeed / RSS / Atom feeds

15218.4k8](/packages/php-feed-io-feed-io)[torann/podcastfeed

Generate RSS feeds for podcasts in Laravel 5.

485.9k](/packages/torann-podcastfeed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
