Edit report at https://bugs.php.net/bug.php?id=50686&edit=1
ID: 50686
Comment by: plenty dot su at gmail dot com
Reported by: thuejk at gmail dot com
Summary: fputcsv and fgetcsv doesn't follow CSV format
Status: Wont fix
Type: Bug
Package: Filesystem function related
Operating System: *
PHP Version: 5.*, 6
Assigned To: iliaa
Block user comment: N
Private report: N
New Comment:
I mentioned in: https://bugs.php.net/bug.php?id=43225
A workaround so far is to disable escape method by: fputcsv($handle, $array, ',',
'"', "\0")
Previous Comments:
------------------------------------------------------------------------
[2017-02-09 17:03:49] aleksey dot spec at gmail dot com
Please, change the behaviour or provide another function. We have problems while preparing csv-files
for ClickHouse.
When I write
$string = '\\"';
fputcsv($fileHandle, [$string]);
I expect to see this in my file:
"\"""
but currently I see
"\""
Csv is often used for communications between different environments, not only inside php with
fputcsv/fgetcsv. so it would be much better if generated csv file obeys some commonly used standard
like RFC 4180.
P.S. Please, do not take personally. I really love php and I'd like it to become even more
beautiful and popular.
------------------------------------------------------------------------
[2016-09-23 17:17:15] office at williamhollandschool dot com
I see that the versions entry only lists 5.* and 6. I use PHP 7 and the "escape" character
thing has caused me no end of grief in trying to implement import and export of natural language
documents into and out of CSV format to later be interpreted by MariaDB's LOAD INFILE. Even
trying the workaround that's posted everywhere of putting the "escape" character the
same as the enclosure character only caused it to fail to escape any enclosure characters. Having to
generate then fix giant files by hand is what has driven me to Python for this task. Many, many
things are still using CSV. Not the most important bug in PHP 7, but one that has annoyed me to no
end.
------------------------------------------------------------------------
[2016-01-05 14:08:11] minexew at gmail dot com
Is there any chance that this will be fixed?
As of today, the documentation for fgetcsv is still misleading and there is no simple workaround.
------------------------------------------------------------------------
[2010-05-30 12:38:14] david at davidhoulder dot com
I've written a CSV parser in PHP that could easily be converted to C to form the basis of a fix
for this.
Go to
http://www.ubercart.org/project/uc_stock_update-2x
and grab the latest uc_stock_update-*.tar.gz
In that tarball you'll find uc_stock_update/ReadCSV.inc which uses a finite state machine to
parse a CSV file. I think it handles RFC4180-compliant files correctly, although it currently
tolerates many error cases. There's a little test suite in uc_stock_update/tests/ . Feedback
welcome (see the download page).
------------------------------------------------------------------------
[2010-04-30 22:35:59] rememb70 at yahoo dot com
Thanks for all your hard work PHP!
Forgive the ego of thuejk and provide replacement functions. It was very disappointing to fully
implement code utilizing these and then discover that they are incompatible with actual csv files.
Thanks.
------------------------------------------------------------------------
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=50686
--
Edit this bug report at https://bugs.php.net/bug.php?id=50686&edit=1