Skip to content

Instantly share code, notes, and snippets.

Last active January 31, 2016 12:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A very basic RSS reader using arc\http, arc\cache, arc\xml and arc\html
* This is a simple demo showing how you can use different components from ARC together
* You can get arc at or with composer:
* composer create-project arc/arc
// load the composer autoloader
require __DIR__ . '/vendor/autoload.php';
// set shorter aliases for the html and xml writer/parser
use \arc\html as h;
use \arc\xml as x;
// create a http proxy with caching based on the cache headers of each request
$client = \arc\cache::proxy( \arc\http::client(), function($params) {
return ( \arc\http\headers::parseCacheTime( $params['target']->responseHeaders ) );
// get a rss feed
$feed = $client->get('');
// parse it, try xml first, but a lot of RSS feeds aren't valid XML
try {
$rss = x::parse($feed);
} catch( \Exception $e ) {
// so in that case parse it as HTML, the ARC API is the same
$rss = h::parse($feed);
// select all 'item' elements, using a CSS selector
$items = $rss->find('item');
// write valid HTML
foreach ($items as $item ) {
echo h::article(
h::h2( h::a( [ 'href' => $item->link->nodeValue ], $item->title->nodeValue ) ),
h::div( [ 'class' => 'body' ], $item->description->nodeValue )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment