Skip to content

Instantly share code, notes, and snippets.

@sweeney
Created April 5, 2010 15:33
Show Gist options
  • Save sweeney/356470 to your computer and use it in GitHub Desktop.
Save sweeney/356470 to your computer and use it in GitHub Desktop.
A way to turn your Dopplr trip feed into a php array of place, start and end timestamps, and lat/lon coordinates. Ugly coding, but it works.
<?php
$url = "YOUR_DOPPLR_FEED_URL"; //Available from http://www.dopplr.com/account - "Atom feed of all your trips"
//-------
$old = array('xmlns=', 'gml:', 'georss:', 'gd:'); //super hack for lack of proper namespace support
$new = array('ns=', 'gml-', 'georss-', 'gd-');
$xml = new SimpleXMLElement(str_replace($old, $new, file_get_contents($url)));
$places = array();
$i=0;
foreach($xml->entry as $entry){
$places[$i]['place'] = strip_tags($entry->title->asXML());
$times = $entry->xpath('gd-when');
$time = $times[0];
$places[$i]['start'] = strtotime(str_replace(array(' startTime="', '"'), '', $time->attributes()->startTime->asXML())) + 3600;
$places[$i]['end'] = strtotime(str_replace(array(' endTime="', '"'), '', $time->attributes()->endTime->asXML())) + 3600; //super hacky and horrid, with an extra hour for TZ mess
$points = $entry->xpath('georss-where/gml-Point');
list($lat, $lon) = explode(' ', trim(strip_tags($points[0]->asXML())));
$places[$i]['lat'] = $lat;
$places[$i]['lon'] = $lon;
$i++;
}
return $places; //Do with this array as you wish.
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment