php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75418 fputcsv() escape parameter meaningless
Submitted: 2017-10-23 13:59 UTC Modified: 2018-02-15 13:22 UTC
From: phofstetter at sensational dot ch Assigned: cmb (profile)
Status: Duplicate Package: Filesystem function related
PHP Version: 7.2.0RC4 OS: macOS, Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phofstetter at sensational dot ch
New email:
PHP Version: OS:

 

 [2017-10-23 13:59 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 17:32 UTC] 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.
 [2018-02-15 13:22 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-02-15 13:22 UTC] cmb@php.net
Closing as duplicate of bug #43225.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC