php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #46872 fgetcsv escape character is misleading
Submitted: 2008-12-15 19:08 UTC Modified: 2009-11-20 11:31 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: jordan dot raub at dataxltd dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
 [2008-12-15 19:08 UTC] jordan dot raub at dataxltd dot com
Description:
------------
the documentation is misleading for fgetcsv.
\ is not the escape char for 5.2.8
double double quotes ("") will escape a double quote w/in a field.

I think the functionality is correct as is, so the docs should just be changed.

see http://en.wikipedia.org/wiki/Comma-separated_values


Reproduce code:
---------------
<?php
$fileContents = <<<EOD
"quote \"testing\"",""
"quote ""testing""",""
EOD;

$handle = fopen('php://memory', 'w');
fwrite($handle, $fileContents);
fseek($handle, 0);

while(!feof($handle))
{
	var_dump(fgetcsv($handle));
}


Expected result:
----------------
array(2) {
  [0]=>
  string(15) "quote "testing""
  [1]=>
  string(4) "test"
}
array(2) {
  [0]=>
  string(17) "quote ""testing"""
  [1]=>
  string(4) "test"
}


Actual result:
--------------
array(2) {
  [0]=>
  string(17) "quote \"testing\""
  [1]=>
  string(4) "test"
}
array(2) {
  [0]=>
  string(15) "quote "testing""
  [1]=>
  string(4) "test"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-15 20:19 UTC] jordan dot raub at dataxltd dot com
tested w/ php5.3alpha3 and got this...

array(2) {
  [0]=>
  string(17) "quote \"testing\""
  [1]=>
  string(4) "test"
}
array(2) {
  [0]=>
  string(15) "quote "testing""
  [1]=>
  string(4) "test"
}
 [2009-11-20 11:31 UTC] vrana@php.net
Escape parameter already documented but seems buggy in PHP 5.3.1. Please report a bug for Filesystem functions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC