tomgould/rsstojson
最新稳定版本:v2.0.1
Composer 安装命令:
composer require tomgould/rsstojson
包简介
Universal RSS/Atom/XML parser that outputs clean JSON-compatible arrays.
README 文档
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.
统计信息
- 总下载量: 270
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-17