I have the output of a GPS route tracker in the format below. Due to problems with the microprocessor code I can not currently use individual files for each track as I would like.
I can not add a special character at the end of each track as I just turn the device off - it does not have many controls. I can add an extra character/row at the start if required and change the first line date time format.
I want to split the large file into each track with the date as the file name.
My idea was to count the data in the file; find a special character e.g. / and split the array on the line above that one but my tests have not been very successfull with the strpos() I was using. Is there an elegant way to do this?
24/5/2019 10:30
0.000000,0.000000,0.0000,0.00
0.000000,0.000000,0.0000,0.00
0.000000,0.000000,0.0000,0.00
53.474474,-2.252000,1.7032,44.60
53.474515,-2.252063,2.3706,40.20
53.474472,-2.252019,1.7377,31.10
53.474482,-2.251990,0.6559,27.40
53.474500,-2.251984,0.4833,27.80
53.474410,-2.251622,5.9265,46.60
53.474591,-2.251822,1.9908,54.20
53.473677,-2.250906,2.8539,9.60
53.473886,-2.251271,1.2774,26.60
53.471829,-2.248942,2.5893,-23.50
53.471148,-2.248520,4.7067,-55.20
53.470708,-2.248306,15.9613,-65.50
53.473323,-2.251162,2.1750,-7.40
53.474106,-2.251974,3.7055,5.40
24/5/2019 16:30
0.000000,0.000000,0.0000,0.00
0.000000,0.000000,0.0000,0.00
0.000000,0.000000,0.0000,0.00
53.474474,-2.252000,1.7032,44.60
53.474515,-2.252063,2.3706,40.20
53.474472,-2.252019,1.7377,31.10
53.474482,-2.251990,0.6559,27.40
53.474500,-2.251984,0.4833,27.80
53.474410,-2.251622,5.9265,46.60
53.474591,-2.251822,1.9908,54.20
53.473677,-2.250906,2.8539,9.60
53.473886,-2.251271,1.2774,26.60
53.471829,-2.248942,2.5893,-23.50
53.471148,-2.248520,4.7067,-55.20
53.470708,-2.248306,15.9613,-65.50
53.473323,-2.251162,2.1750,-7.40
53.474106,-2.251974,3.7055,5.40
<?php
if (($handle = fopen("GPSdata.txt", 'r')) !== FALSE) {
$lines = array();
while (($data = fgetcsv($handle, 100, ",")) !== FALSE) {
echo $data[0].'<br>';
if( $data[0] != "0.000000" )// Ignore "empty" lines
{
$gps[] = $data;
}
}
fclose($handle);
}
echo '<pre>';
print_r($gps);
echo '</pre>';
$data1 = "";
foreach ($gps as $key => $val)
{
$row = array(); // reset to empty
foreach ($val as $key2 => $val2)
{
$row[] = $val2;
}
$formatted_row_data = join(',', $row);
$data1 .= $formatted_row_data . "\n";
}
echo '<pre>';
print_r($data1);
echo '</pre>';
?>
Out of interest a couple of photos of the device: