|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72945 Allow to pass empty string as $escape to fgetcsv()
Submitted: 2016-08-26 09:16 UTC Modified: 2016-08-26 13:58 UTC
From: alex at shopblocks dot com Assigned: cmb (profile)
Status: Duplicate Package: Filesystem function related
PHP Version: 7.0.10 OS: Mac OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: alex at shopblocks dot com
New email:
PHP Version: OS:


 [2016-08-26 09:16 UTC] alex at shopblocks dot com
fgetcsv is not correctly getting all of the rows for a CSV file

Test CSV file:

As you can see, the file is valid and imports correctly into GitHub, OS X Numbers and Excel.

Test script:
function dd()
    echo '<pre>';
    array_map(function ($x) {
    }, func_get_args());


$csv = fopen("test.csv", 'r');

$headers = fgetcsv($csv);
$row = fgetcsv($csv);

dd($headers, $row);

Expected result:
All 21 columns should be filled

Actual result:
only 15 columns get filled

    [0] => id
    [1] => name
    [2] => variants
    [3] => sku
    [4] => price_web
    [5] => price_rrp
    [6] => price_cost
    [7] => quantity
    [8] => visible
    [9] => status
    [10] => tax_id
    [11] => images
    [12] => price_prefix
    [13] => price_modifier
    [14] => text
    [15] => product_video
    [16] => tax_rate
    [17] => attribute
    [18] => attribute_value
    [19] => manufacturer
    [20] => category_id
    [0] => 1009
    [1] => Halcyon Scout Light
    [2] => Add a Boltsnap§90mm Stainless Steel Boltsnap§+4.0743
    [3] => HalcyonScout
    [4] => 121.6667
    [5] => 121.667
    [6] => 0.000
    [7] => 1
    [8] => 1
    [9] => 0
    [10] => 1
    [11] => 9282§Halcyon_Scout_Light.jpg§Halcyon_Scout_Light.jpg
    [12] => +
    [13] => 4.0743
    [14] => 
Several Halcyon products evolved out of necessity: the  performance of available manufactured gear was not acceptable under rigorous  mission critical situations. The Scout is just such a product. 

The Scout  is machined out of a solid rod of delrin for strength and fitted with a proper  voltage bulb to reduce the risk of failure. Nearly all widely available reserve  lights overdrive the bulb to create a brighter beam. While overdriving the bulb  is effective for short term use, it increases the stress on the filament,  resulting in a greater frequency of bulb failure. 

The Scout has a  machined attachment point at the rear of the light and is free from all the  plastic clips and other assorted snags typically present on mass manufactured  lights. 

Machined from a solid rod of delrin 

5.5 watt bulb 

Approx 3.5 hour burn time 

Uses 3 x C cell batteries (not included)



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-26 12:59 UTC]
-Summary: CSV Cannot be read properly +Summary: Allow to pass empty string as $escape to fgetcsv() -Type: Bug +Type: Feature/Change Request -Package: *General Issues +Package: Filesystem function related
 [2016-08-26 12:59 UTC]
That behavior is caused by fgetcsv() catering for an escape
character (what is pretty much uncommon for CSV). The default
escape character is a backslash, so the attributes values which
contain only a backslash break the parser. You can easily work
around this issue by overriding the escape character to use a
character that isn't contained in the CSV, e.g.

  fgetcsv($csv, 0, ',', '"', '|');

I'm changing this ticket to a feature request, because it would be
useful to be able to pass an empty string as $escape, so the
behavior of fgetcsv() would be more compliant to other CSV
 [2016-08-26 13:58 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-08-26 13:58 UTC]
Actually, there is already request #51496, so I'm closing this as
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 04:01:28 2024 UTC