PHP cuenta línea / fila en el archivo de texto basado en la columna de valor
Continuar con mi @ anteripregunt.
Tengo un archivo de registro de texto llamado rechazar. Puedes verloaqu
omo puede ver, hay 4 pasos en la pestaña llamada:
1. Battery level
2. Piezo sound level
3. Left D3 (Ch 3) light intensity
4. Right D2 (Ch 1) light intensity
Ahora quiero contar cada fila con condición:
Which column(Steps) value is filled then count it.
Example: on row 1, We can see the value 0 (any value) is on step Piezo sound level. Then count it.
or lo tanto, finalmente puedo saber cuántas cantidades rechazar el proces
Battery level = x quantity
Piezo sound level = x quantity
Left D3 (Ch 3) light intensity = x quantity
Right D2 (Ch 1) light intensity = x quantity
El código PHP:
$fromDateTime = new DateTime('Wed, Sep 19 2018 08:00:00');
$toDateTime = new DateTime('Wed, Sep 19 2018 19:59:00');
$file = file_get_contents('reject.txt');
$lines = explode("\n",$file);
// counter
$rowsintimespan = 0;
// Do Line-By-Line starting by Line 16 (Array Index 15)
for($i = 15; $i < count($lines); $i++) {
// if the file is "Tue, Sep 18<tab>2018<tab>23:59:53<tab>"
$dateobj = DateTime::createFromFormat("???,?M?d??Y?H:i:s+", $lines[$i]);
// check if date is in your Timespan
if($dateobj < $toDateTime && $dateobj > $fromDateTime) {
$rowsintimespan++; // count if in timespan
}
}
// Debug-Output
echo $rowsintimespan;
ACTUALIZA
Necesito leer el último valor de la columna. Ejemplo: si el valor de la fila está en la columna D3 izquierda, entonces cuéntelo. Si el valor de la fila está en la columna Piezo, cuéntelo.