0

I have csv files I would like to combine into a single csv file. I have managed to remove all headers. The headers write to the new file in the right column and row. But the rows from from the csv files are not lining up they start from column B instead of column A. Data from the csv is put in an array added to the new file. Is there a way I could remove the trailing commas and invoke a PHP_EOL. Here is an example of an element with data.

Array([0]=>"Joe,Soap,,,25,11,,,,,,"
[1]=>"Jimmy,Tesla,10,,4,,,,,,,,")

I would like each element to write on new line starting from column A. Here is my script.

 $fileload = $filecontents;
        $lines = file($fileload);
        foreach ($lines as $key => $line) {
          $lineArr = explode(',',$line);
          if(count(array_filter($lineArray)) <= 3)
          {
            continue;
          }
          if(count(array_intersect($lineArr, $outputheaders)) >= 1)
          {
            continue;
          }
      //Row Data
          $parts[] = $line;

        }

  $headers = implode(",",$putheaders);
  $sTmp = $sTmp.$headers;
  $details = implode("','",$parts);
  $sTmp = $sTmp.$details;


file_put_contents($Out, $sTmp, FILE_APPEND | LOCK_EX);
Cœur
  • 37,241
  • 25
  • 195
  • 267
saiyan101
  • 610
  • 4
  • 12
  • 28

0 Answers0