1. Go to this page and download the library: Download debril/feed-io library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
debril / feed-io example snippets
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
$feedIo = \FeedIo\FeedIo($client);
// read a feed
$result = $feedIo->read($url);
// get title
$feedTitle = $result->getFeed()->getTitle();
// iterate through items
foreach( $result->getFeed() as $item ) {
echo $item->getTitle();
}
// read a feed and specify the `$modifiedSince` limit to fetch only items newer than this date
$result = $feedIo->read($url, $feed, $modifiedSince);
// iterate through new items
foreach( $result->getItemsSince() as $item ) {
echo $item->getTitle();
}
// read a feed
$result = $feedIo->read($url, $feed, $modifiedSince);
// remove items older than `$modifiedSince`
$since = new FeedIo\Filter\Since($result->getModifiedSince());
// Your own filter
$database = new Acme\Filter\Database();
$chain = new Chain();
$chain
->add($since)
->add($database);
// iterate through new items
foreach( $result->getFilteredItems($chain) as $item ) {
echo $item->getTitle();
}
$nextUpdate = $result->getNextUpdate();
echo "computed next update: {$nextUpdate->format(\DATE_ATOM)}";
// you may need to access the statistics
$updateStats = $result->getUpdateStats();
echo "average interval in seconds: {$updateStats->getAverageInterval()}";
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
$feedIo = \FeedIo\FeedIo($client);
$feeds = $feedIo->discover($url);
foreach( $feeds as $feed ) {
echo "discovered feed : {$feed}";
}
// build the feed
$feed = new FeedIo\Feed;
$feed->setTitle('...');
// convert it into Atom
$atomString = $feedIo->toAtom($feed);
// or ...
$atomString = $feedIo->format($feed, 'atom');
$feed = new FeedIo\Feed;
$feed->setTitle('...');
$styleSheet = new StyleSheet('http://url-of-the-xsl-stylesheet.xsl');
$feed->setStyleSheet($styleSheet);
// build the feed
$feed = new FeedIo\Feed;
$feed->setTitle('...');
$item = $feed->newItem();
// add namespaces
$feed->setNS(
'itunes', //namespace
'http://www.itunes.com/dtds/podcast-1.0.dtd' //dtd for the namespace
);
$feed->set('itunes,title', 'Sample Title'); //OR any other element defined in the namespace.
$item->addElement('itunes:category', 'Education');
// build the media
$media = new \FeedIo\Feed\Item\Media
$media->setUrl('http://yourdomain.tld/medias/some-podcast.mp3');
$media->setType('audio/mpeg');
// add it to the item
$item->addMedia($media);
$feed->add($item);
$feed = new \FeedIo\Feed;
// feed the beast ...
$item = new \FeedIo\Feed\Item;
$item->set ...
$feed->add($item);
$atomResponse = $feedIo->getPsrResponse($feed, 'atom');
$jsonResponse = $feedIo->getPsrResponse($feed, 'json');
// first dependency : the HTTP client
// here we use Guzzle as a dependency for the client
$guzzle = new GuzzleHttp\Client();
// Guzzle is wrapped in this adapter which is a FeedIo\Adapter\ClientInterface implementation
$client = new FeedIo\Adapter\Guzzle\Client($guzzle);
// second dependency : a PSR-3 logger
$logger = new Psr\Log\NullLogger();
// now create FeedIo's instance
$feedIo = new FeedIo\FeedIo($client, $logger);
// create a simple FeedIo instance, e.g. with the Symfony HTTP Client
$client = new \FeedIo\Adapter\Http\Client(new Symfony\Component\HttpClient\HttplugClient());
$logger = new Monolog\Logger('default', [new Monolog\Handler\StreamHandler('php://stdout')]);
$feedIo = \FeedIo\FeedIo($client, $logger);
use FeedIo\FeedIo;
use FeedIo\Adapter\Guzzle\Client;
use GuzzleHttp\Client as GuzzleClient;
use Custom\Logger;
$client = new Client(new GuzzleClient());
$logger = new Logger();
$feedIo = new FeedIo($client, $logger);
use CustomPsr18\Client as CustomClient;
$client = new Custom\Adapter\Http\Client(new CustomClient())
$logger = new Psr\Log\NullLogger();
$feedIo = new FeedIo\FeedIo($client, $logger);