php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26915 fgetcsv and quoted enclosures
Submitted: 2004-01-15 05:21 UTC Modified: 2004-01-15 05:35 UTC
From: juergen at henge-ernst dot de Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.4 OS:
Private report: No CVE-ID: None
 [2004-01-15 05:21 UTC] juergen at henge-ernst dot de
Description:
------------
The following line in a csv-file does not get parsed correctly:
"one\""one","two\\two","three""three","four\""four"

For me the csv format is defined as:
If a delimiter is used inside a string/entry, the entry must be enclosured with a character. If the encloure-character is used inside the entry, the enclosure character must be doubled.

maybe the fix of Bug #22382 "fgetcsv does not allow escaped quotes" introduced this behaviour.

With version 4.2.2, 4.2.3 the correct string is returned.

Reproduce code:
---------------
$str = '"one\""one","two\\\\two","three""three","four\""four"';
$x=fopen("x.csv","w");
fputs($x, $str);
fclose($x);
$x=fopen("x.csv","r");
while ($y=fgetcsv($x,1000,","))
 var_dump($y);


Expected result:
----------------
array(4) {
  [0]=>
  string(5) "one\"one"
  [1]=>
  string(8) "two\\two"
  [2]=>
  string(11) "three"three"
  [3]=>
  string(6) "four\"four"
}


Actual result:
--------------
array(4) {
  [0]=>
  string(5) "one\""
  [1]=>
  string(8) "two\\two"
  [2]=>
  string(11) "three"three"
  [3]=>
  string(6) "four\""
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-15 05:35 UTC] juergen at henge-ernst dot de
ok seems to be fixed in php4-STABLE-200401150830
PHP 4.3.5RC2-dev (cli)
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Dec 06 11:05:52 2022 UTC