php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37942 fgetcsv strips certain characters from beginning of a field if not quoted
Submitted: 2006-06-28 08:43 UTC Modified: 2006-06-28 09:52 UTC
From: bugs dot php dot net_alex at gareis dot info Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.1.4 OS: Linux (Debian)
Private report: No CVE-ID: None
 [2006-06-28 08:43 UTC] bugs dot php dot net_alex at gareis dot info
Description:
------------
Despite the correct locale settings, fgetcsv strips characters from the beginning of a field, if the field is not quoted correctly.

Reproduced with PHP 5.1.2-Debian-0.1~sarge1, PHP 5.1.4-1.dotdeb.2, locales en_US, en_US.UTF-8, POSIX.

NOT reproduced with PHP 5.0.5-2ubuntu1.2 (en_US.UTF-8), 5.1.4-Debian-0.1~sarge1 (en_US)

Might actually not be a bug, but a documentation problem - however, i do not think this related to the similar bug reports present.

Reproduce code:
---------------
#!/usr/local/bin/php -Cq
<?php

if (is_file('temp')) die("temp!\n");

$fcontent = 'foo,?bar,?????,"?bar","?????"';
file_put_contents('temp', $fcontent);
echo 'plain: '.file_get_contents('temp')."\n\nfgetcsv: ";
$fp = fopen('temp', 'r');
print_r(fgetcsv($fp, 1024, ',', '"'));
fclose($fp);
unlink('temp');

?>


Expected result:
----------------
plain: foo,?bar,?????,"?bar","?????"

fgetcsv: Array
(
    [0] => foo
    [1] => ?bar
    [2] => ?????
    [3] => ?bar
    [4] => ?????
)


Actual result:
--------------
plain: foo,?bar,?????,"?bar","?????"

fgetcsv: Array
(
    [0] => foo
    [1] => bar
    [2] =>
    [3] => ?bar
    [4] => ?????
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-28 09:52 UTC] bugs dot php dot net_alex at gareis dot info
Obviously i was wrong.

Though calls to setlocale() resulted in no error, they did not have any effect, as "locales" was not installed on the systems where the error was reproduced.

Now, with working locales and setting "en_US.iso8859-1" the CSVs parse just fine.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 30 15:01:27 2020 UTC