php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30476 fgetcsv treats \" incorectly
Submitted: 2004-10-18 23:29 UTC Modified: 2004-10-19 00:14 UTC
From: andy at invocation dot ltd dot uk Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.9 OS: Linux
Private report: No CVE-ID: None
 [2004-10-18 23:29 UTC] andy at invocation dot ltd dot uk
Description:
------------
The function fgetcsv assumes that a \ within a line of a CSV file is an escape character, this is inconsistant with the csv output of most (if not all) applications.

For example:

"foo","bar\","wombat"

Is 3 fields, but fgetcsv interprets this as 2 fields as the quote at the end of bar is considered escaped. 

Both Open Office and Microsoft Works (hence probably also Excel) would genrate the above line from a spreadsheet looking like:

1       2        3
foo     bar\     wombat

Gnumeric does not put quotes round each text field unless it has to (i.e. contains a " or , in the text) but if you have:

foo     b,ar\    wombat

you get:

foo,"b,ar\",wombat

This would again, I suspect, confuse the php fgetcsv function.

I appreciate that the csv file format is not covered by any proper standards but it would be nice if its behaviour could be made compatable with popular spreadsheets.

This is essentialy the same report is someone else submitted (#28347). This was rejected, unfairly in my opinion, as bogus.



Reproduce code:
---------------
See Bug #28347 for example code and results.

Expected result:
----------------
See Bug #28347 for example code and results.

Actual result:
--------------
See Bug #28347 for example code and results.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-18 23:52 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

There is only so much magic PHP can do to fix broken CSV feeds. The current behaviour is correct.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 23:01:32 2024 UTC