dg/rss-php

RSS & Atom Feeds for PHP 是一个非常小巧且易于使用的库,用于消费 RSS 和 Atom 流

维护者

详细信息

github.com/dg/rss-php

主页

源代码

安装数: 863,039

依赖者: 13

推荐者: 0

安全性: 0

星标: 473

关注者: 31

分支: 148

v1.5 2020-11-25 22:57 UTC

This package is auto-updated.

Last update: 2024-09-06 10:22:24 UTC


README

Downloads this Month Latest Stable Version License

RSS & Atom Feeds for PHP 是一个非常小巧且易于使用的库,用于消费 RSS 和 Atom 流。

它需要 PHP 5.3 或更高版本,带有 CURL 扩展或启用 allow_url_fopen,并采用新 BSD 许可证授权。您可以从我们的 GitHub 仓库 获取最新版本,或通过 Composer 安装。

composer require dg/rss-php

支持我

你喜欢 RSS 吗?你在期待新功能吗?

Buy me a coffee

谢谢!

使用方法

从 URL 下载 RSS 流

$rss = Feed::loadRss($url);

返回的属性是 SimpleXMLElement 对象。从频道中提取信息非常简单

echo 'Title: ', $rss->title;
echo 'Description: ', $rss->description;
echo 'Link: ', $rss->url;

foreach ($rss->item as $item) {
	echo 'Title: ', $item->title;
	echo 'Link: ', $item->url;
	echo 'Timestamp: ', $item->timestamp;
	echo 'Description ', $item->description;
	echo 'HTML encoded content: ', $item->{'content:encoded'};
}

从 URL 下载 Atom 流

$atom = Feed::loadAtom($url);

您还可以启用缓存

Feed::$cacheDir = __DIR__ . '/tmp';
Feed::$cacheExpire = '5 hours';

如果需要,您可以设置 User-Agent

Feed::$userAgent = "FeedFetcher-Google; (+http://www.google.com/feedfetcher.html)";

如果您喜欢它,请 现在捐款。谢谢!