Skip to content

Instantly share code, notes, and snippets.

@rmccue
Created December 7, 2009 07:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmccue/250682 to your computer and use it in GitHub Desktop.
Save rmccue/250682 to your computer and use it in GitHub Desktop.
Normalise SimplePie items to put into a database
<?php
require('simplepie.inc');
$feed = new SimplePie('http://example.com/feed/');
foreach($feed->get_items() as $item) {
$new_item = (object) array(
'hash' => $item->get_id(true),
'timestamp' => $item->get_date('U'),
'title' => $item->get_title(),
'content' => $item->get_content(),
'summary' => $item->get_description(),
'permalink' => $item->get_permalink(),
'metadata' => (object) array(
'enclosure' => $enclosure
),
'author' => (object) $author,
'feed' => $item->get_feed()->get_link()
);
$items[] = $new_item;
}
// Save item array to database, where $database is some sort of DB interface
$database->save_items($items);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment