tomgould / rsstojson
Universal RSS/Atom/XML parser that outputs clean JSON-compatible arrays.
Installs: 230
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tomgould/rsstojson
Requires
- php: >=7.4
- ext-curl: *
- ext-libxml: *
Requires (Dev)
- phpunit/phpunit: ^9.5
README
RSStoJSON is a PHP library that parses RSS, Atom, or generic XML feeds (including MRSS video feeds) into structured, JSON-compatible arrays. It works with remote URLs or local files and is designed to be framework-agnostic.
๐ Features
- Supports RSS, Atom, MRSS (Media RSS), and XML feeds
- Works with local file paths or remote URLs
- Handles namespaced elements and attributes (e.g.,
media:content,media:thumbnail) - JSON-encoding ready output
- Includes CLI tool for terminal use
- PHP 7.4+ compatible (works with Drupal 8, 9, 10, 11, and other modern PHP frameworks)
- Composer-ready for easy installation
๐ฆ Installation
Via Composer:
composer require tomgould/rsstojson
๐ Usage
Programmatic
<?php require 'vendor/autoload.php'; use TomGould\RSSToJson\RSSToJson; $parser = new RSSToJson(); $feed = $parser->parse('https://example.com/feed.xml'); echo json_encode($feed, JSON_PRETTY_PRINT);
Parse Local Files
<?php require 'vendor/autoload.php'; use TomGould\RSSToJson\RSSToJson; $parser = new RSSToJson(); $feed = $parser->parse('/path/to/local/feed.xml'); echo json_encode($feed, JSON_PRETTY_PRINT);
CLI
After installing via composer, you can use the CLI tool:
vendor/bin/rsstojson https://example.com/feed.xml
Or if installed globally:
rsstojson https://example.com/feed.xml
๐ Examples
See the /examples directory for sample code:
examples/parse-url.php- Parse a remote feedexamples/parse-local.php- Parse a local MRSS video feed
๐งช Testing
Run the test suite:
composer test
Or using PHPUnit directly:
vendor/bin/phpunit tests
๐ฅ MRSS Support
This library fully supports Media RSS (MRSS) feeds, commonly used for video content. It properly handles namespaced elements like:
media:content- Video URLs and metadatamedia:thumbnail- Video thumbnail imagesmedia:category- Content categoriesmedia:keywords- Content tags
See tests/sample-mrss.xml for an example MRSS feed structure.
๐ง Requirements
- PHP 7.4 or higher
- ext-libxml
- ext-curl
๐ชช License
MIT โ free for commercial and personal use.
๐ค Contributing
Issues and pull requests are welcome on the GitHub repository.