moell/rss是遵循RSS2.0標準的PHP包,Laravel版本請查看moell/laravel-rssphp
moell/rss
moell/laravel-rsshtml
http://www.rssboard.org/rss-specificationlaravel
PHP >= 5.4.0git
composer require "moell/rss:1.*"
//設置字符集 public function setEncode($encode); //默認UTF-8 public function channel(array $channel); public function item(array $item); public function items(array $items); //構造xml public function build(); //快速構造 public function fastBuild(array $channel, array $item); public function __toString();
$rss = new \Moell\Rss\Rss(); $channel = [ 'title' => 'title', 'link' => 'http://moell.cn', 'description' => 'description', 'category' => [ 'value' => 'html', 'attr' => [ 'domain' => 'http://www.moell.cn' ] ] ]; $rss->channel($channel); $items = []; for($i = 0; $i < 2; $i++) { $item = [ 'title' => "title".$i, 'description' => 'description', 'source' => [ 'value' => 'moell.cn', 'attr' => [ 'url' => 'http://www.moell.cn' ] ] ]; $items[] = $item; $rss->item($item); } echo $rss; //獲取xml //其餘獲取方式 $rss->build()->asXML(); $rss->fastBuild($channel, $items)->asXML(); $rss->channel($channel)->items($items)->build()->asXML();
<?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>title</title> <link>http://moell.cn</link> <description>description</description> <category domain="http://www.moell.cn">html</category> <item> <title>title0</title> <description>description</description> <source url="http://www.moell.cn">moell.cn</source> </item> <item> <title>title1</title> <description>description</description> <source url="http://www.moell.cn">moell.cn</source> </item> </channel> </rss>
MITgithub
若是你喜歡本項目,歡迎star。GitHub
轉帖需說明文章出處:http://moell.cn/article/25shell