php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42210 fputcsv() not consistent to enclose with other than default enclosure value
Submitted: 2007-08-05 12:33 UTC Modified: 2007-08-06 16:22 UTC
From: nikhil dot gupta at in dot ibm dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5CVS-2007-08-05 (CVS) OS: Linux, Win32-xp
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: nikhil dot gupta at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-08-05 12:33 UTC] nikhil dot gupta at in dot ibm dot com
Description:
------------
fputcsv() is behaving differently with different fields values. A string provided with a blank space gets enclosed by fputcsv but with other characters other than space are not enclosed. For details refer to the reproduce code and expected and actual output.

Reproduce code:
---------------
<?php
$fh = fopen("file.tmp","w");
$field_array = array('abc,def');
$field_array2 = array('abc def');
var_dump( fputcsv($fh, $field_array, '+', '$') );
fclose($fh);

var_dump( file_get_contents("file.tmp") );
unlink("file.tmp");
$fh = fopen("file2.tmp","w");
var_dump( fputcsv($fh, $field_array2, '+', '$') );
fclose($fh);

var_dump( file_get_contents("file2.tmp") );
?>

Expected result:
----------------
int(8)
string(8) "$abc,def$
"
int(10)
string(10) "$abc def$
"

Actual result:
--------------
int(8)
string(8) "abc,def
"
int(10)
string(10) "$abc def$
"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-06 16:22 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The CSV definition does not require all values to be enclosed in quoting 
char. PHP only does so when needed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 02:01:33 2025 UTC