michaelhall/rss-feed

PHP的简单RSS订阅创建器

v3.0.0 2022-09-19 16:00 UTC

This package is auto-updated.

Last update: 2024-09-19 20:38:41 UTC


README

Tests StyleCI License Latest Stable Version Total Downloads

简单的RSS订阅创建器。

需求

  • PHP >= 8.0

使用Composer安装

$ composer require michaelhall/rss-feed

基本用法

<?php

require __DIR__ . '/vendor/autoload.php';

use DataTypes\Net\Url;
use MichaelHall\RssFeed\RssFeed;
use MichaelHall\RssFeed\RssItem;

// Create the feed.
$feed = new RssFeed(
    'Feed Title',
    Url::parse('https://example.com/'),
    'The feed description.'
);

// This is optional but recommended by W3C feed validator.
$feed->setFeedUrl(Url::parse('https://example.com/path/to/feed'));

// Add an item.
$feedItem = new RssItem(
    'Item Title',
    Url::parse('https://example.com/path/to/item-page'),
    'The item description',
    new DateTimeImmutable('2017-08-22 19:56:00')
);

$feed->addItem($feedItem);

// Prints the RSS feed.
echo $feed;

向订阅中添加图片

use MichaelHall\RssFeed\RssImage;

$feedImage = new RssImage(
    Url::parse('https://example.com/path/to/image'),
    'Image Title',
    Url::parse('https://example.com/')
);

$feed->setImage($feedImage);

许可证

MIT