#22382 [NEW]: fgetcsv does not allow escaped quotes

From: Date: Sun, 23 Feb 2003 01:45:00 +0000
Subject: #22382 [NEW]: fgetcsv does not allow escaped quotes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-33950@lists.php.net to get a copy of this message
From:             Stevenv at operamail dot com
Operating system: FreeBSD 4.7
PHP version:      4.3.0
PHP Bug Type:     Filesystem function related
Bug description:  fgetcsv does not allow escaped quotes

As the summary says, fgetcsv does not allow escaped quotes. When csv fields
come from user input, it is often the case that addslashes() is run on
them then enclosed in quotes. However, fgetcsv() removes anything after
the escaped quote.

Code:

<?php
/* make a csv file */
$fp = fopen('csv_file', 'w+');
$fields = array();

$fields[0] = '"' . addslashes('This is "Field One"') .
'"';
$fields[1] = 'field two';
$fields[2] = 'field three';
fwrite($fp, implode(',', $fields));

/* start all over */
fseek($fp, 0);
var_dump(fgetcsv($fp, 4096));
?>

Outputs:
array(3) {
  [0]=>
  string(9) "This is \"
  [1]=>
  string(9) "field two"
  [2]=>
  string(11) "field three"
}

The behavior I expected would have been for the first field to read:
"This is \"Field One\""

Much like the functionality described on
<http://rath.ca/Misc/Perl_CSV/CSV-2.0.html#csv
specification>.

Thanks
-- 
Edit bug report at http://bugs.php.net/?id=22382&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=22382&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=22382&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=22382&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=22382&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=22382&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=22382&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=22382&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=22382&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=22382&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=22382&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22382&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=22382&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=22382&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=22382&r=gnused



Thread (7 messages)

« previous php.bugs (#33950) next »