Ed9c50a6db8b5e078b5ef84306a8477c

Uses ARC RDF parser from http://arc.semsol.org/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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 !

Ebc3a0e54f61babe2d060f6404f7aa13

Paul Stamatiou

February 25, 2008, February 25, 2008 06:47, permalink

1 rating. Login to rate!

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

Ed9c50a6db8b5e078b5ef84306a8477c

hubfactor

March 5, 2008, March 05, 2008 17:58, permalink

No rating. Login to rate!

SimpleXML isn't an RDF parser, so that wouldn't be better.

65705c17914ae0eae9ebda2b20702875

ea neil

March 9, 2008, March 09, 2008 17:29, permalink

No rating. Login to rate!

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/ ) ?

Your refactoring





Format Copy from initial code

or Cancel