ID:               43225
 Updated by:       [email protected]
 Reported By:      ed at bronto dot com
-Status:           No Feedback
+Status:           Open
 Bug Type:         Filesystem function related
 Operating System: Centos
 PHP Version:      5.2.4
 New Comment:

This bug is the same as bug #38918 and bug #38929.

* fputcsv() does escape values (replacing " with "", for example)
* It seems that fgetcsv() accepts two incompatible unescaping methods

Reproduced:
php > $fp = fopen('php://temp', 'r');
php > fputcsv($fp, array('foo', 'bar\\', 'baz'));
php > rewind($fp);
php > echo fgets($fp);
foo,"bar\",baz
php > rewind($fp);
php > var_dump(fgetcsv($fp));
array(2) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(10) "bar\",baz
"
}
php > echo PHP_VERSION;
5.2.6-pl7-gentoo
php > 

I believe this problem is due to the fact fgetcsv() accept two escaping
methods. An extra argument to fgetcsv() could (maybe?) fix this (and the
extra argument could be added to fputcsv too)


Previous Comments:
------------------------------------------------------------------------

[2008-07-22 01:00:00] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------

[2008-07-14 21:26:41] [email protected]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi



------------------------------------------------------------------------

[2008-04-17 01:00:55] dan at expireddomain dot com

Same problem on windows XP PHP version 5.2.5 on cells that contain a \
followed by double quotes (")

------------------------------------------------------------------------

[2007-11-09 14:59:11] ed at bronto dot com

Description:
------------
Using fputcsv to output a cell that ends with a \ followed by double
quotes (") causes it to not use any escape sequence.  Oddly, fgetscsv is
able to parse it correctly.  Unlike fgetscsv, I assume fputcsv follows
RFC 4180 and uses " as the escape character.

Reproduce code:
---------------
$row = array();
$row[] = 'a\\"';
$row[] = 'bbb';

$fp = fopen('test.csv', 'w+');
fputcsv($fp, $row);
fclose($fp);






Expected result:
----------------
expected output: "a\""",bbb

Actual result:
--------------
actual output: "a\"",bbb


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=43225&edit=1

Reply via email to