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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 22:01:32 2024 UTC