Skip to content

Instantly share code, notes, and snippets.

@imelgrat
Created February 15, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imelgrat/fa0cec291e40ec550767d6aa859fa3b7 to your computer and use it in GitHub Desktop.
Save imelgrat/fa0cec291e40ec550767d6aa859fa3b7 to your computer and use it in GitHub Desktop.
Use an open source PHP class to fetch articles from RSS, ATOM and OPML feeds
<?php
/**
* Retrieve and parse OPML (Outline Processor Markup Language) Parser Class.
* Extracts the properties of content from OPML files using a PHP class
*
* @link https://github.com/imelgrat/opml-parser
*
* @link https://imelgrat.me/php/find-atom-opml-rss-feeds/
*/
require_once('opml-parser.php');
use imelgrat\OPML_Parser\OPML_Parser;
$parser = new OPML_Parser();
// Get OPML from URL
$parser->ParseLocation('http://www.bbc.co.uk/podcasts.opml', null);
// Walk through each item in the same way as we would if $parser were a string (thanks to the Iterator interface)
foreach ($parser as $key => $item)
{
echo "<p> Item: " . $key . '</p><ul>';
foreach ($item as $attribute => $value)
{
echo '<li>' . '<strong>' . $attribute . '</strong>:' . $value . '</li>';
}
echo '</ul>';
echo '<p>&nbsp;</p>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment