php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27378 Fgetcsv not quite handling enclosures properly
Submitted: 2004-02-24 10:36 UTC Modified: 2004-02-24 16:51 UTC
From: sthomas at townnews dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4CVS-2004-02-24 (stable) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sthomas at townnews dot com
New email:
PHP Version: OS:

 

 [2004-02-24 10:36 UTC] sthomas at townnews dot com
Description:
------------
Fgetcsv appears to have been rewritten from 4.3.4 which was a bit buggy.  But there is still one unresolved issue with csv parsing I noticed in tests where the enclosure character is stripped from the text regardless of its enclosure status if it begins the string, but does not end the string.

Reproduce code:
---------------
Example file:

blabla,"stuff with thing",yay
foo,stuff with "thing",moo
blarg,"stuff" with thing,goop

Script:

<?PHP

$fp = fopen("/tmp/ctext.txt", "r");
while ($aLine = fgetcsv($fp, 8192, '|', '"'))
{
  print_r($aLine);
}
fclose($fp);

?>


Expected result:
----------------
Array
(
    [0] => blabla
    [1] => stuff with thing
    [2] => yay
)
Array
(
    [0] => foo
    [1] => stuff with "thing"
    [2] => moo
)
Array
(
    [0] => blarg
    [1] => "stuff" with thing
    [2] => goop
)


Actual result:
--------------
Note the missing quotes around "stuff" in the third array.  I can only assume beginning the string with quotes makes PHP think the whole string is quoted, so it strips the first and second quotes it finds.

Array
(
    [0] => blabla
    [1] => stuff with thing
    [2] => yay
)
Array
(
    [0] => foo
    [1] => stuff with "thing"
    [2] => moo
)
Array
(
    [0] => blarg
    [1] => stuff with thing
    [2] => goop
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-24 16:51 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is how it is supposed to work, I've tried this in Open 
Office & MS Office (excel) and got the same data as the one 
generated by PHP. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Sep 14 14:00:02 2025 UTC