suin / php-rss-writer
适用于PHP 5.4或更高版本的另一个简单的RSS编写库。
1.6.0
2017-07-13 10:47 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- eher/phpunit: >=1.6
- mockery/mockery: >=0.7.2
- suin/xoopsunit: >=1.2
README
\Suin\RSSWriter
是适用于PHP 5.4或更高版本的另一个简单RSS编写库。该组件遵循MIT许可证。
此库还可以用于发布播客。
快速演示
$feed = new Feed(); $channel = new Channel(); $channel ->title('Channel Title') ->description('Channel Description') ->url('http://blog.example.com') ->feedUrl('http://blog.example.com/rss') ->language('en-US') ->copyright('Copyright 2012, Foo Bar') ->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900')) ->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900')) ->ttl(60) ->pubsubhubbub('http://example.com/feed.xml', 'http://pubsubhubbub.appspot.com') // This is optional. Specify PubSubHubbub discovery if you want. ->appendTo($feed); // Blog item $item = new Item(); $item ->title('Blog Entry Title') ->description('<div>Blog body</div>') ->contentEncoded('<div>Blog body</div>') ->url('http://blog.example.com/2012/08/21/blog-entry/') ->author('John Smith') ->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900')) ->guid('http://blog.example.com/2012/08/21/blog-entry/', true) ->preferCdata(true) // By this, title and description become CDATA wrapped HTML. ->appendTo($channel); // Podcast item $item = new Item(); $item ->title('Some Podcast Entry') ->description('<div>Podcast body</div>') ->url('http://podcast.example.com/2012/08/21/podcast-entry/') ->enclosure('http://podcast.example.com/2012/08/21/podcast.mp3', 4889, 'audio/mpeg') ->appendTo($channel); echo $feed; // or echo $feed->render();
输出
<?xml version="1.0" encoding="UTF-8"?> <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> <channel> <title>Channel Title</title> <link>http://blog.example.com</link> <description>Channel Description</description> <language>en-US</language> <copyright>Copyright 2012, Foo Bar</copyright> <pubDate>Tue, 21 Aug 2012 10:50:37 +0000</pubDate> <lastBuildDate>Tue, 21 Aug 2012 10:50:37 +0000</lastBuildDate> <ttl>60</ttl> <atom:link rel="self" href="http://example.com/feed.xml" type="application/rss+xml"/> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/> <item> <title><![CDATA[Blog Entry Title]]></title> <link>http://blog.example.com/2012/08/21/blog-entry/</link> <description><![CDATA[<div>Blog body</div>]]></description> <content:encoded><![CDATA[<div>Blog body</div>]]></content:encoded> <guid>http://blog.example.com/2012/08/21/blog-entry/</guid> <pubDate>Tue, 21 Aug 2012 10:50:37 +0000</pubDate> <author>John Smith</author> </item> <item> <title>Some Podcast Entry</title> <link>http://podcast.example.com/2012/08/21/podcast-entry/</link> <description><div>Podcast body</div></description> <enclosure url="http://podcast.example.com/2012/08/21/podcast.mp3" type="audio/mpeg" length="4889"/> </item> </channel> </rss>
安装
简单安装
您可以直接通过Composer进行安装
$ composer require suin/php-rss-writer
手动安装
将以下代码添加到您的composer.json
文件中
{ "require": { "suin/php-rss-writer": ">=1.0" } }
...然后运行composer进行安装
$ composer install
最后,在您的产品中包含vendor/autoload.php
require_once 'vendor/autoload.php';
如何使用
examples
目录包含RSSWriter的用法示例。
如果您想了解API,请参阅FeedInterface
、ChannelInterface
和ItemInterface
。
如何测试
$ vendor/bin/phpunit
通过PHP 5.4 ~ PHP 7.0进行测试
$ docker-compose up
许可证
MIT许可证