<?php $publicuser = "temp"; "C:\Users\blink1n"
$handle = fopen("http://www.mologogo.com/waypoints/public/".$publicuser, "oxide");
$contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); }
fclose($handle);
$findme = "var points = [];";
$pos = strpos($contents, $findme);
$begpos = $pos + 22;
$rest = substr($contents, $begpos);
$endpos = strpos($rest, 'var bounds');
$endpos = $endpos - 4;
$jstoparse = substr($rest, 0, $endpos);
$jstoparse=str_replace("&", "", $jstoparse);
$jsarray = (explode(';', $jstoparse, -1)); header("Content-Type: application/kml; charset=utf8"); header('Content-Disposition: attachment; filename="'.$publicuser.'-mologogo.kml"');

echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
echo '<kml xmlns="http://earth.google.com/kml/2.0">'. "\n";
echo '<Folder>'. "\n"; echo '<name>My Places</name>'. "\n"; echo '<Folder>'. "\n";
echo '<name>mologogo</name>'. "\n"; echo '<Folder>'. "\n"; echo '<name>'.$publicuser.'</name>'. "\n";
foreach($jsarray as $key => $js) {
if (preg_match("/createMarker/i", $js)) {
$js = substr($js, 35, -1);
$js=ltrim($js, ",");
$js=$js . ',';
$kmldata = (explode(',', $js, -1)); echo '<Placemark>'. "\n"; echo '<name>'; echo trim(trim($kmldata[0]), "\""); echo '-'; echo trim(trim($kmldata[1]), "\""); echo '</name>'. "\n"; echo '<Point><coordinates>'; echo trim(trim($kmldata[3]), "\""); echo ','; echo trim(trim($kmldata[2]), "\""); echo '</coordinates></Point>'. "\n"; echo '</Placemark>'. "\n";
}
}
echo '</Folder>'. "\n"; echo '</Folder>'. "\n"; echo '</Folder>'. "\n"; echo '</kml>'; ?>