Edit report at http://bugs.php.net/bug.php?id=53848&edit=1

 ID:                 53848
 Comment by:         phillip at grueter-online dot de
 Reported by:        andre at webkr dot de
 Summary:            fgetcsv ignores spaces on beginning of line
 Status:             Open
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Windows 7
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

Same problem in version 5.2.10



shell > php --version

PHP 5.2.10-2ubuntu6.5



php > var_dump(file("csvtest.csv"));

array(3) {

  [0]=>

  string(4) "a,b

"

  [1]=>

  string(5) " c,d

"

  [2]=>

  string(1) "

"

}

php > $handle = fopen("csvtest.csv", "r");

php > $a = fgetcsv($handle);

php > var_dump($a);

array(2) {

  [0]=>

  string(1) "a"

  [1]=>

  string(1) "b"

}

php > $a = fgetcsv($handle);

php > var_dump($a);

array(2) {

  [0]=>

  string(1) "c"

  [1]=>

  string(1) "d"

}


Previous Comments:
------------------------------------------------------------------------
[2011-01-26 13:49:48] andre at webkr dot de

Description:
------------
RFC4180 says: "Spaces are considered part of a field and should not be
ignored."



However (despite being the only CSV parsing function that fulfils all
other requirements), fgetcsv ignores spaces at the very beginning of a
record.

Test script:
---------------
/*



Put this in a file:

a,b

 c,d



*/



$fd = fopen('the_file','r');

$a = fgetcsv($fd);

Expected result:
----------------
array( array('a', 'b'), array(' c','d') )

Actual result:
--------------
array( array('a', 'b'), array('c','d') )


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53848&edit=1

Reply via email to