How to format a txt file, inserting columns and changing format of date and time with script in php

1

I have text file generated from an access control device, when down the file it comes without columns of identification, what do I need to do? Insert columns and paste the date format so that the file can be imported into mysql. This way I can see: Thanks for the help!

This is a part of the file, a row with a total of 8 columns:

0000000001 001 00000000000090000001 01/01/2014 00:00:38 1 0 5
    
asked by anonymous 10.10.2016 / 17:30

1 answer

0

This solution should help you:

<?php
$linha  = "0000000001 001 00000000000090000001 01/01/2014 00:00:38 1 0 5";
$partes = explode(" ", $linha);
$i = 0;
foreach ($partes as $campo) {
    echo 'campo' . ++$i . ' = ' .  $campo . "\n"; 
}

Results in:

campo1 = 0000000001
campo2 = 001
campo3 = 00000000000090000001
campo4 = 01/01/2014
campo5 = 00:00:38
campo6 = 1
campo7 = 0
campo8 = 5

In practice, you simply get each element of the $partes array and place it within each specific field you want. Ex:

mysql_campo1 = $partes[0];
mysql_campo2 = $partes[1];
mysql_campo3 = $partes[2];
.
.
.

See working at link

    
04.06.2018 / 03:41