celd/opml-import-export

用于导入和导出OPML格式(RSS/Atom)订阅源列表的库。

dev-master 2014-08-12 20:08 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:35:59 UTC


README

导入/导出OPML格式的订阅源列表。

安装

使用composer安装。

导入OPML文件

<?php
use Celd\Opml\Importer;
$importer = new Importer(file_get_contents('http://opml-url'));
$feedList = $importer->getFeedList();
foreach ($feedList->getItems() as $item) {
  if ($item->getType() == 'category') {
    echo $item->getTitle(); // Category title
    foreach($item->getFeeds() as $feed) {
      echo $feed->getTitle() . "\n";
    }
  }
  echo $item->getTitle(); //Root feed title
}

// Properties of Model/Feed are:
// title, xmlUrl, htmlUrl, type (rss/atom/etc)

导出OPML文件

<?php
use Celd\Opml\Importer;
use Celd\Opml\Model\FeedList;
use Celd\Opml\Model\Feeed;

$feedList = new FeedList();

$feed = new Feed();
$feed->setTitle('Feed title');
$feed->setXmlUrl('http://rss-feed-url');
$feed->setType('rss');
$feed->setHtmlUrl('http://html-url');

$feedList->addItem($feed);

$importer = new Importer();
echo $importer->export($feedList);