moell/rss 好用的轮子,轻松实现网站RSS功能,遵循RSS2.0标准

moell/rss

moell/rss是遵循RSS2.0标准的PHP包,Laravel版本请查看moell/laravel-rss

源码地址

moell/rss
moell/laravel-rss

RSS规范

http://www.rssboard.org/rss-specification

要求

PHP >= 5.4.0

安装

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();

生成结果



    
        title
        http://moell.cn
        description
        html
        
            title0
            description
            moell.cn
        
        
            title1
            description
            moell.cn
        
    

License

MIT

如果你喜欢本项目,欢迎star。GitHub
转帖需说明文章出处:http://moell.cn/article/25

你可能感兴趣的:(moell/rss 好用的轮子,轻松实现网站RSS功能,遵循RSS2.0标准)