Edit report at http://bugs.php.net/bug.php?id=53848&edit=1
ID: 53848
Comment by: dave at roweware dot com
Reported by: andre at webkr dot de
Summary: fgetcsv ignores spaces at beginnings of fields
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 for me on Ubuntu 10.04 - PHP 5.3.2
I would much prefer to control if/when the fields are trimmed via
trimming them
myself, or via a flag.
Previous Comments:
------------------------------------------------------------------------
[2011-04-16 19:51:33] andre at webkr dot de
Indeed, I overlooked that.
I added your data to my test (without the quotes and line break, of
course) and I can confirm that issue. I changed the summary accordingly.
------------------------------------------------------------------------
[2011-04-15 19:49:51] mark dot mccray at tbwachiat dot com
Same issue on Mac OS X 10.6.7 running PHP ver 5.3.4.
------------------------------------------------------------------------
[2011-04-15 19:40:41] mark dot mccray at tbwachiat dot com
Forgot to add that we are on hp-ux 11.11i. Php ver 5.2.4.
------------------------------------------------------------------------
[2011-04-15 19:40:08] mark dot mccray at tbwachiat dot com
I'm posting a comment here instead of a bug because I feel we may be
encountering the same issue.
My problem is that fgetcsv seems to trim whitespace at the beginning of
any
field -- not just at the beginning of a record.
In a record (our files are separated by a pipe symbol):
"001|00005964_154|OGLCV|003|
174699|USD|0326049|Corporation||000000|11/03/27||11/04/14|1|MPY||CP"
The field " 174699" gets inserted into the array as "174699".
We are expecting the leading whitespace to not be trimmed.
------------------------------------------------------------------------
[2011-02-11 14:50:52] phillip at grueter-online dot de
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"
}
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=53848
--
Edit this bug report at http://bugs.php.net/bug.php?id=53848&edit=1