1

When I read the CSV (with PHPExcel, of fgetcsv()) I want to import in my database rows are cut off.

1 fields in line 1: 
  ProCatId;CatName;CatDescription;CatNameisactive;CatNameiswebactive;ProSubCatId;SubCatName;SubCatDesc;SubcatWebDiscription2;SubcatWebDiscription3;SubcatCatName;SubcatSequencenr;SubCatNameisactive;SubCatNameiswebactive;DisplayMode;ProductId;ProductName;ProductDescription;ProductCatName;ProductSubCatName;Express;NextDayDelivery;Sequencenr;Drukvorm;Afwerking;BreedteDrukwerk;HoogteDrukwerk;Papier;PrinterName;PrinterProductCode;WebDescription;WebDescription2;WebDescription3;DeliveryInfo;NextDayPrice;NextDayTransferPrice;NextDayCostPrice;Meta-Keywords;Meta-Description;URL-Trefwoorden;Titel;Filepath_icons;Format;MaterialType;NoOfPages;PrintFront;PrintBack;BleedTop;BleedBottom;BleedLeft;BleedRight;MINH;MAXH;MINW;MAXW;De
1 fields in line 2: 
  liveryScheduleId;DeliveryScheduleName;CentralProductDetailId;ClaimsId;ClaimsName;DruktechniekenId;DruktechniekenName;Verzameld op;Vast;Variabel;vorm;"prijs
1 fields in line 3: 
  drukken

These field are supposed to be all in line 1. When I use the php function file_get_contents() the content looks valid. Loading the file in Excel gives also no problems.

I use the following code (, seperated):

<?php 
if (($handle = fopen($inputFileName, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}
?>
Dyam
  • 33
  • 5

1 Answers1

0

Let us see what the documentation says:

array fgetcsv ( 
        resource $handle 
        [, int $length = 0 
        [, string $delimiter = ","
        [, string $enclosure = '"'
        [, string $escape = "\" ]]]] )

You are passing in a $handle, good.

You are saying "cut off a line at 1000 characters" - with your data, this might become a problem, consider a higher limit (8000?)

And you are saying "fields are separated by ,". It looks as if they're actually separated by ;. Perhaps this is also a part of the problem?

(Also, fgetcsv is not binary-safe, so if your data is not plain ASCII, see this question.)

Community
  • 1
  • 1
Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
  • When I use the following instead of fgetcsv(). " while (($raw_data = fgets($handle, 100000)) !== FALSE) { ", the first two rows are one. But it still cuts off the third. – Dyam Feb 26 '16 at 09:25