php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38929 fputcsv() fgetcsv() inconsistency even number backslashes then enclosure char
Submitted: 2006-09-22 20:05 UTC Modified: 2006-09-25 12:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: mike at opendns dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.1.6 OS: Linux, debian sarge
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mike at opendns dot com
New email:
PHP Version: OS:

 

 [2006-09-22 20:05 UTC] mike at opendns dot com
Description:
------------
If you write a string to file with fputcsv that contains an even number of backslashes follwed by the enclosure character, you don't get your enclosure character back when you read it back in with fgetcsv().  Then you'll get an extra trailing enclosure character at the end of your string.

Reproduce code:
---------------
$tmp_file = '/tmp/csv_f_up.tmp';

$data_to_write = array('string contains even number of backslashes \\\\" followed by enclosure char');

echo "data_to_write:\n";
var_dump($data_to_write);

$h_w = fopen($tmp_file, 'w');
fputcsv($h_w, $data_to_write);
fclose($h_w);

$h_r = fopen($tmp_file, 'r');
$data_read_in = fgetcsv($h_r);
fclose($h_r);

echo "data_read_in:\n";
var_dump($data_read_in);

Expected result:
----------------
data_to_write:
array(1) {
  [0]=>
  string(73) "string contains even number of backslashes \\" followed by enclosure char"
}
data_read_in:
array(1) {
  [0]=>
  string(73) "string contains even number of backslashes \\" followed by enclosure char"
}

Actual result:
--------------
data_to_write:
array(1) {
  [0]=>
  string(73) "string contains even number of backslashes \\" followed by enclosure char"
}
data_read_in:
array(1) {
  [0]=>
  string(73) "string contains even number of backslashes \\ followed by enclosure char""
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-25 12:24 UTC] tony2001@php.net
The same problem as #38918.
 [2010-08-03 10:21 UTC] surfchen at gmail dot com
I confirm this with php 5.2.9 on windows:
$arr=array('\\','"');
$h=fopen('test.csv',"w");
fputcsv($h,$arr);
fclose($h);

$h=fopen('test.csv',"r");
$line=fgetcsv($h);
var_dump($line);

result:
array(1) {
  [0]=>
  string(6) "\",""
"
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC