#46872 [NEW]: fgetcsv escape character is misleading

From: Date: Mon, 15 Dec 2008 19:08:55 +0000
Subject: #46872 [NEW]: fgetcsv escape character is misleading
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1635@lists.php.net to get a copy of this message
From:             jordan dot raub at dataxltd dot com
Operating system: *
PHP version:      Irrelevant
PHP Bug Type:     Documentation problem
Bug description:  fgetcsv escape character is misleading

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"
}


-- 
Edit bug report at http://bugs.php.net/?id=46872&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        http://bugs.php.net/fix.php?id=46872&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        http://bugs.php.net/fix.php?id=46872&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        http://bugs.php.net/fix.php?id=46872&r=trysnapshot60
Fixed in CVS:                        http://bugs.php.net/fix.php?id=46872&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46872&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=46872&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=46872&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=46872&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=46872&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=46872&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=46872&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=46872&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=46872&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=46872&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=46872&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=46872&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=46872&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=46872&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=46872&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=46872&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=46872&r=mysqlcfg



Thread (3 messages)

« previous php.doc.bugs (#1635) next »