lib16/rss

lib16 RSS Builder 是一个用于创建 RSS 源的 PHP 7 库。

v1.1 2020-12-27 07:06 UTC

This package is auto-updated.

Last update: 2024-09-27 15:17:39 UTC


README

这是一个用 PHP 7 编写的创建 RSS 源的库。

Build Status Coverage

使用 Composer 安装

此包可在 packagist 上找到,因此您可以使用 Composer 安装它。请在您的 shell 中运行以下命令

composer require lib16/rss

基本用法

以下示例标记来自 en.wikipedia.org/wiki/Rss

<?php
require_once 'vendor/autoload.php';

use Lib16\RSS\Channel;
use Lib16\RSS\RssMarkup;

$channel = Channel::create(
    'RSS Title',
    'This is an example of an RSS feed',
    'http://www.example.com/main.html'
);
$channel
    ->pubDate(new DateTime('2010-09-06 00:01 +0'))
    ->lastBuildDate(new DateTime('2009-09-06 16:20 +0'))
    ->ttl(1800);

$channel
    ->item(
        'Example entry',
        'Here is some text containing an interesting description.',
        'http://www.example.com/blog/post/1'
    )
    ->guid('7bd204c6-1655-4c27-aeee-53f933c5395f', false)
    ->pubDate(new DateTime('2009-09-06 16:20 +0'));

RssMarkup::headerfields('example');
print $channel;

… 生成以下输出

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
    <channel>
        <title>RSS Title</title>
        <description>This is an example of an RSS feed</description>
        <link>http://www.example.com/main.html</link>
        <pubDate>Mon, 06 Sep 2010 00:01:00 +0000</pubDate>
        <lastBuildDate>Sun, 06 Sep 2009 16:20:00 +0000</lastBuildDate>
        <ttl>1800</ttl>
        <item>
            <title>Example entry</title>
            <description>Here is some text containing an interesting description.</description>
            <link>http://www.example.com/blog/post/1</link>
            <guid isPermaLink="false">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
            <pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
        </item>
    </channel>
</rss>