ma4nn / php-rss-writer
又一个简单的RSS编写库。
3.0.0
2024-07-12 10:34 UTC
Requires
- php: ^8.2
- ext-dom: *
- ext-libxml: *
- ext-simplexml: *
Requires (Dev)
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11
Replaces
- suin/php-rss-writer: 1.6.0
This package is auto-updated.
Last update: 2024-09-12 11:15:37 UTC
README
\Suin\RSSWriter
是一个针对PHP的简单RSS编写库。本组件采用MIT许可。
该库也可用于发布播客。
此原始包的分支主要提高了PHP兼容性至 >= 8.2 并提升了代码质量。
快速演示
$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.com') ->creator('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.com</author> <creator>John Smith</creator> </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 ma4nn/php-rss-writer
如何使用
examples
目录包含了RSSWriter的使用示例。
如需了解API,请参阅FeedInterface
、ChannelInterface
和ItemInterface
。
如何测试
$ vendor/bin/phpunit
使用Docker测试旧版PHP版本
$ docker-compose up
许可
MIT许可