Req #51496 [Asn]: fgetcsv should take empty string as an escape
Edit report at https://bugs.php.net/bug.php?id=51496&edit=1
ID: 51496
Updated by: cmb@php.net
Reported by: kulakov74 at yandex dot ru
Summary: fgetcsv should take empty string as an escape
Status: Assigned
Type: Feature/Change Request
Package: Filesystem function related
Operating System: All
PHP Version: 5.3.2
Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
Any news here? In my opinion, this feature is a must-have, because
escaping in CSV files with an escape character is pretty uncommon,
and I'm not even sure how $escape is supposed to work currently
(see bug #67566).
Previous Comments:
------------------------------------------------------------------------
[2016-08-26 13:58:43] cmb@php.net
Related To: Bug #72945
------------------------------------------------------------------------
[2014-12-02 14:06:08] datibbaw@php.net
I'm currently making my way through all reported issues against CSV related functions in order
to fix them for PHP 7.
I believe that this particular issue can be resolved by using the double quote as both the enclosure
AND escape character; in fact, this should be the default, because a backslash makes no sense at all
if you consider other applications such as Numbers, Excel and Calc that do not treat a backslash as
anything special.
------------------------------------------------------------------------
[2012-04-10 21:02:39] laurent at chardin dot org
fgetcsv should also take empty strings as an enclosure.
I got the case of dealing with CSV files without enclosures, only comma-delimited
values. fgetcsv complains when trying to set either of those values:
NULL
'\0'
using '\0' did the trick, but at the cost of a tons of warnings:
fgetcsv(): enclosure must be a single character
Is there another caracter that could act as an empty one ?
------------------------------------------------------------------------
[2011-07-19 17:43:09] conrad1 at gmail dot com
fgetcsv does NOT get the cells right if the last characte from a cell is \
How to replicate:
//you can also try this with fopen('file.csv')
$body =
"\"cell1\",\"cell2\\\",\"cell3\",\"cell4\"";
$filename = 'data://text/plain;base64,'.base64_encode($body);
$fp = fopen($filename,"r");
$a = fgetcsv($fp,10000,',','"');
print_r($a);
This will output
Array
(
[0] => cell1
[1] => cell2\",cell3"
[2] => cell4
)
------------------------------------------------------------------------
[2010-04-08 06:58:55] aharvey@php.net
Sounds reasonable to me. It probably wouldn't hurt to allow the enclosure to accept an empty
string as well.
I'll cook something up for trunk and we can decide whether we want this in 5.3 from there.
------------------------------------------------------------------------
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
https://bugs.php.net/bug.php?id=51496
--
Edit this bug report at https://bugs.php.net/bug.php?id=51496&edit=1
Thread (10 messages)