We are working with a fingerprint scanner for attendance, it generates these kind of text files
1,MARCOS,MORENO,12:29,15:58,2020-02-26
2,ALEJANDRO,BASAL,12:05,18:01,2020-02-26
3,CARMEN,MORIA,11:58,17:59,2020-02-26
We want to upload it to our site, load the file, split that text into lines and then each line into arrays, to work with them, like so:
Array1 ([0] => 1 [1] => MARCOS [2] => MORENO [3] => 12:29 [4] => 15:58 [5] => 2020-02-26)
Array2 ([0] => 2 [1] => ALEJANDRO [2] => BASAL[3] => 12:05 [4] => 18:01 [5] => 2020-02-26)
Array3 ([0] => 3 [1] => CARMEN[2] => MORIA [3] => 11:58 [4] => 17:59 [5] => 2020-02-26)
To then load each array into a database. Each [0] going into id, [1] into name, etc. We managed to load and read the file, however we are unsure on how to split the file like we want to, so far our code only splits the full array without taking into account the line breaks, it returns this
Array ([0] => 1 [1] => MARCOS [2] => MORENO [3] => 12:29 [4] => 15:58 [5] => 2020-02-26 [6] => 2 [7] => ALEJANDRO [8] => BASAL[9] => 12:05 [10] => 18:01 [11] => 2020-02-26 [12] => 3 [13] => CARMEN[14] => MORIA [15] => 11:58 [16] => 17:59 [17] => 2020-02-26)
Each line is an employee and each line will always have the same amount of splits (by commas). Maybe if its not possible to split by line breaks just being able to handle additions will be enough (handle every [0]s with [6]s, [12]s, [18]s and so on together). To then update values in our database.
Our code right now is really simple, just
$file= 'attendance/' . '{file}';
$doc=file_get_contents($file);
$line=explode("\n",$doc);
foreach($line as $newline){
echo '<h3 style="color:#453288">'.$newline.'</h3><br>';
}
'.$newline.'
'; } – Maximiliano Corbo Feb 27 '20 at 21:32