PHP code example of juststeveking / feed-parser

1. Go to this page and download the library: Download juststeveking/feed-parser 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/ */

    

juststeveking / feed-parser example snippets


use JustSteveKing\FeedParser\AtomParser;
use JustSteveKing\FeedParser\FeedIterator;
use JustSteveKing\FeedParser\ValueObjects\AtomEntry;
use JustSteveKing\FeedParser\ValueObjects\AtomFeed;

$iterator = new FeedIterator(
    url: 'https://example.com/feed.atom',
    parser: new AtomParser(),
);

/** @var AtomFeed $item */
foreach ($iterator as $item) {
    echo $item->title(); // The Title of the Feed
    echo $item->link(); // The Link of the Feed
    echo $item->subtitle(); // The Subtitle of the Feed
    echo $item->updated(); // The Updated Date of the Feed
    echo $item->rights(); // The Rights of the Feed
    echo $item->generator(); // The Generator of the Feed

    /** @var AtomEntry $entry */
    foreach ($item->entries() as $entry) {
        echo $entry->title(); // The Title of the Entry
        echo $entry->link(); // The Link of the Entry
        echo $entry->id(); // The ID of the Entry
        echo $entry->updated(); // The Updated Date of the Entry
        echo $entry->summary(); // The Summary of the Entry
        echo $entry->content(); // The Content of the Entry
        echo $entry->author(); // The Author of the Entry
    }
}

use JustSteveKing\FeedParser\RssParser;
use JustSteveKing\FeedParser\FeedIterator;
use JustSteveKing\FeedParser\ValueObjects\RssChannel;
use JustSteveKing\FeedParser\ValueObjects\RssItem;

$iterator = new FeedIterator(
    url: 'https://example.com/feed.rss',
    parser: new RssParser(),
);

/** @var RssChannel $item */
foreach ($iterator as $item) {
    echo $item->title(); // The Title of the Feed
    echo $item->link(); // The Link of the Feed
    echo $item->description(); // The Description of the Feed

    /** @var RssItem $entry */
    foreach ($item->items() as $entry) {
        echo $entry->title(); // The Title of the Entry
        echo $entry->link(); // The Link of the Entry
        echo $entry->guid(); // The GUID of the Entry
        echo $entry->pubDate(); // The Published Date of the Entry
        echo $entry->description(); // The Description of the Entry
        echo $entry->author(); // The Author of the Entry
    }
}