Skip to content

Instantly share code, notes, and snippets.

@findzen
Created May 22, 2012 00:11
Show Gist options
  • Save findzen/2765591 to your computer and use it in GitHub Desktop.
Save findzen/2765591 to your computer and use it in GitHub Desktop.
Parse Twitter RSS feed and cache using SimplePie
<?php
require_once 'lib/simplepie.inc';
require_once 'lib/json_format.php';
$response = array(
'tweets' => parse_feed( 'http://search.twitter.com/search.atom?q=from%3acnnbrk+OR+from%3anpratc' )
);
function parse_feed( $url )
{
$data = array();
$feed = new SimplePie( $url );
foreach ( $feed->get_items() as $feed_item )
{
$item[ 'author' ] = array(
'name' => $feed_item->get_author()->get_name(),
'link' => $feed_item->get_author()->get_link(),
'image' => $feed_item->get_link( 0, 'image' )
);
$item[ 'title' ] = $feed_item->get_title();
$item[ 'timestamp' ] = $feed_item->get_date();
$data[] = $item;
}
return $data;
}
header( 'Content-type: text/javascript; charset=UTF-8' );
echo json_format( json_encode( $response ) );
/* EOF */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment