Edit report at https://bugs.php.net/bug.php?id=75418&edit=1
ID: 75418
Updated by: cmb@php.net
Reported by: phofstetter at sensational dot ch
Summary: fputcsv() escape parameter meaningless
-Status: Open
+Status: Duplicate
Type: Bug
Package: Filesystem function related
Operating System: macOS, Linux
PHP Version: 7.2.0RC4
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Closing as duplicate of bug #43225.
Previous Comments:
------------------------------------------------------------------------
[2017-10-24 17:32:41] cmb@php.net
> It looks like that parameter is meaningless though as of all the
> possible values passed in, only " really does something [â¦]
That's not quite right, see
<https://externals.io/message/100729#100729>,
for instance.
> [â¦] and what it does is break the CSV encoding.
Indeed, using the $escape parameter with fputcsv() can easily
produce non-standard CSV (if there were such a standard).
Frankly, I do not know which use-case has been targetted by
introducing the $escape parameter.
------------------------------------------------------------------------
[2017-10-23 13:59:31] phofstetter at sensational dot ch
Description:
------------
Since 5.4.4 there's an escape_char parameter that's defaulting to \.
It looks like that parameter is meaningless though as of all the possible values passed in, only
" really does something and what it does is break the CSV encoding.
Test script:
---------------
<?php
$fh = fopen('php://stdout', 'w');
fputcsv($fh, ['using default', 'a,"b'], ',', '"');
fputcsv($fh, ['using " ', 'a,"b'], ',',
'"', '"');
fputcsv($fh, ['using x ', 'a,"b'], ',', '"',
'x');
fputcsv($fh, ['using \\ ', 'a,"b'], ',', '"',
'\\');
Expected result:
----------------
"using default","a,\"b"
"using " ","a,""b"
"using x ","a,x"b"
"using \ ","a,\"b"
Actual result:
--------------
"using default","a,""b"
"using " ","a,"b"
"using x ","a,""b"
"using \ ","a,""b"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75418&edit=1