【问题标题】:Reading Excel csv using PHP Rows are cut off使用 PHP 读取 Excel csv 行被切断
【发布时间】:2016-02-25 11:12:29
【问题描述】:

当我读取 CSV(使用 PHPExcel,fgetcsv())时,我想在我的数据库中导入的行被截断。

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

这些字段应该都在第 1 行。 当我使用 php 函数 file_get_contents() 时,内容看起来有效。 在 Excel 中加载文件也没有问题。

我使用以下代码(,分隔):

<?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);
}
?>

【问题讨论】:

  • 我尝试盲注.. 替换“;”用“,”

标签: php excel csv phpexcel fgetcsv


【解决方案1】:

让我们看看documentation 是怎么说的:

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

你传入了$handle,很好。

您是说“在 1000 个字符处截断一行” - 对于您的数据,这可能会成为问题,请考虑更高的限制(8000?)

您是在说“字段由, 分隔”。看起来它们实际上; 分隔。也许这也是问题的一部分?

(另外,fgetcsv 不是二进制安全的,所以如果您的数据不是纯 ASCII,see this question。)

【讨论】:

  • 当我使用以下而不是 fgetcsv() 时。 " while (($raw_data = fgets($handle, 100000)) !== FALSE) { ",前两行是一。但它仍然切断了第三个。
猜你喜欢
  • 2016-03-08
  • 2013-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-07
  • 1970-01-01
相关资源
最近更新 更多