<?php
require_once("arc/ARC2.php"); // http://arc.semsol.org/
$url = 'http://www.google.com/'; // URL to investigate
$ns_rss = 'http://purl.org/rss/1.0/';
$ns_dc = 'http://purl.org/dc/elements/1.1/';
$ns_rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
$md5_url = md5($url);
$rss_url = 'http://del.icio.us/rss/url/' . $md5_url;
$html_url = 'http://del.icio.us/url/' . $md5_url;
$rdf = file_get_contents($rss_url);
$parser = ARC2::getRDFXMLParser();
$parser->parse($rss_url, $rdf);
$root = $parser->getSimpleIndex();
$channel = $root["$html_url"];
$items_id = $channel[$ns_rss . 'items'][0];
$items = $root["$items_id"];
$output = array();
foreach ($items as $key => $triple){
$item = $root["$triple[0]"]; // pick out the individual item by ID
if ($item[$ns_rdf . 'type'][0] == $ns_rss . 'item'){ // if it's an "rss item"
$output[] = array(
'creator' => $item[$ns_dc . 'creator'][0],
'tags' => $item[$ns_dc . 'subject'][0],
'description' => $item[$ns_rss . 'description'][0],
);
}
}
print_r($output);
Refactorings
No refactoring yet !
Paul Stamatiou
February 25, 2008, February 25, 2008 06:47, permalink
What version of PHP are you using? If 5+ you can make this a whole lot shorter with SimpleXML: http://paulstamatiou.com/2007/04/17/how-to-parse-xml-with-php5
hubfactor
March 5, 2008, March 05, 2008 17:58, permalink
SimpleXML isn't an RDF parser, so that wouldn't be better.
ea neil
March 9, 2008, March 09, 2008 17:29, permalink
First question; is the "creator" the person who posted the uri?
Second question; how would I get the "creator" data from the del.icio.us most popular page ( http://del.icio.us/popular/ ) ?
Uses ARC RDF parser from http://arc.semsol.org/