-
Notifications
You must be signed in to change notification settings - Fork 0
/
garmin2csv.php
executable file
·59 lines (42 loc) · 1.03 KB
/
garmin2csv.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/php -q
<?
$latitude = null;
$longitude = null;
$altitude = null;
$time = null;
$in_element = null;
function characterData($parser, $data) {
GLOBAL $latitude, $longitude, $altitude, $time;
GLOBAL $in_element;
switch($in_element) {
case "TIME":
$time = $data;
break;
case "LATITUDEDEGREES":
$latitude = $data;
break;
case "LONGITUDEDEGREES":
$longitude = $data;
break;
case "ALTITUDEMETERS":
$altitude = $data;
break;
}
}
function startElement($parser, $name, $attrs) {
GLOBAL $in_element;
$in_element = $name;
}
function endElement($parser, $name) {
GLOBAL $latitude, $longitude, $altitude, $time;
GLOBAL $in_element;
$in_element = null;
if($name == "TRACKPOINT")
echo "$time, $latitude, $longitude, $altitude\n";
}
$xml_parser = xml_parser_create("UTF-8");
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parse($xml_parser, file_get_contents($_SERVER['argv'][1]));
xml_parser_free($xml_parser);
?>