0

I have this function that reads csv file line by line and looks for specific label in the first column of each row and then if label was found it reads all the columns next to this found label into array until column value is empty. It used to work fine, but recently I have noticed it started skipping the very first row in the file.

If i add an empty line at the top of the file it reads the row just fine, but how do i make it read from the very first line again?

I use PHP Version 5.5.18 and php version was upgraded not so long ago, if it is PHP version bug downgrading the version is not the solution for me...

Is there any alternative functions or maybe a way to force it to read from the first line or maybe suggestion on how to make this happen?

function getDataByLabel($label){

   if(($filePointer = fopen($this->path, "r"))!==FALSE){

       //reading each line
        while (($data = fgetcsv($filePointer, 0, ",",'"')) !== FALSE) {

            if(trim(strtolower($data[0]))==trim(strtolower($label))){ 

               $i=0;
               $c=1;

        // if column is not empty we add this value to an array
               while(!empty($data[$c])){
                    $label = trim(ucfirst(strtolower($label)));
                    $this->param[$label][$i] = $data[$c];
                    $i++;
                    $c++;
                }

            }

        }
    }
}
steven
  • 4,868
  • 2
  • 28
  • 58
anonymous007
  • 319
  • 1
  • 3
  • 12

1 Answers1

-1

When you save csv file as UTF8-with Signature, it will skip the first row. using Emeditor, save as UTF8-Without Signature, will not skip 1st row.

Metoo
  • 1