How to ignore first line of csv file

0

I need to ignore the first line of a file I'm importing into csv with php, that first line is a header, any hint how can I do this? I tried to make an accountant, but I could not solve it, what I have is this:

if (!empty($_FILES)) {

    $tempFile = $_FILES['userImage']['tmp_name'];
    $Dados = file($tempFile);

    foreach($Dados as $RegLinhas) {

        // RETIRA ESPAÇOS NO INÍCIO E FIM
        $Linha = trim($RegLinhas);
        // DIVIDE A STRING
        $CamposImport = explode(';', $Linha);
        $IdPessoa = $CamposImport[0];       
        $Nome = $CamposImport[1];
        $IdUnicoop = $CamposImport[2];
        $DataAdmissao = $CamposImport[3];
        $IdCargo = $CamposImport[4];
        $LotacaoRH = $CamposImport[5];
        $CTPS = $CamposImport[6];
        $CTPSSerie = $CamposImport[7];
        $CTPSUF = $CamposImport[8];
        $DataNascimento = $CamposImport[9];
        $CPF = $CamposImport[11];

    }           
}
    
asked by anonymous 08.02.2018 / 11:10

1 answer

0

You can do the following to remove the first array item, array_shift() :

...
$Dados = file($tempFile);
array_shift($Dados); // remover primeira linha, primeiro elemento do array
...

DEMONSTRATION

Although the way above is the simplest / best, here is a way without using function:

...
foreach($Dados as $key => $RegLinhas) {
    if($key == 0) continue; // saltar para a prox volta caso seja a primeira linha
    ...
}

DEMONSTRATION

    
08.02.2018 / 11:18