dansup / rss-php
此包已被弃用且不再维护。没有建议的替代包。
RSS & Atom Feeds for PHP 是一个用于消费 RSS 和 Atom 的非常小巧且易于使用的库。
1.3.0
2017-09-17 03:34 UTC
Requires
- php: ^5.6 || ^7.0
- guzzlehttp/guzzle: ^6.2
README
RSS & Atom Feeds for PHP 是一个用于消费 RSS 和 Atom 的非常小巧且易于使用的库。此项目是从 David Grudl 的 rs-php https://github.com/dg/rss-php 分支出来的。
它需要 PHP 5.5 和 Guzzle 6.1,并使用新的 BSD 许可证授权。您可以从我们的 GitHub 仓库 获取最新版本,或者通过 Composer 安装。
php composer.phar require dansup/rss-php
使用
从 URL 下载 RSS 源
$rss = Feed::loadRss($url);
返回的属性是 SimpleXMLElement 对象。从频道中提取信息非常简单
echo 'Title: ', $rss->title; echo 'Description: ', $rss->description; echo 'Link: ', $rss->link; foreach ($rss->item as $item) { echo 'Title: ', $item->title; echo 'Link: ', $item->link; echo 'Timestamp: ', $item->timestamp; echo 'Description ', $item->description; echo 'HTML encoded content: ', $item->{'content:encoded'}; }
从 URL 下载 Atom 源
$atom = Feed::loadAtom($url);
您可以将自己的 Guzzle 实例设置到静态客户端属性
Feed::$client = new GuzzleHttp\Client(['headers' => ['User-Agent' => 'FeedPHP/1.0']]);
它将被重用。
您可以在每次调用时传递 Guzzle 请求选项(包括认证用户/密码)
$atom = Feed::loadAtom($url, ['auth' => ['peter', 'secret']);
您还可以使用 https://github.com/Kevinrob/guzzle-cache-middleware 启用缓存
// Simple volatile memory cache example check docs for more options use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use Kevinrob\GuzzleCache\CacheMiddleware; // Create default HandlerStack $stack = HandlerStack::create(); // Add this middleware to the top with `push` $stack->push(new CacheMiddleware(), 'cache'); // Initialize the client with the handler option Feed::$client = new Client(['handler' => $stack]);
(c) David Grudl, 2008 (http://davidgrudl.com) (c) grunjol, 2017 (https://github.com/grunjol) (c) dansup, 2017 (https://github.com/dansup)