ID: 13950
Updated by: derick
Reported By: [EMAIL PROTECTED]
Old Status: Assigned
Status: Closed
Bug Type: Documentation problem
Operating System: Sun (SPARC) Solaris 2.6
PHP Version: 4.0.6 / 4.20cvs
Old Assigned To: jeroen
Assigned To: 
New Comment:

Closing due to no feedback

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

[2001-11-08 17:01:30] [EMAIL PROTECTED]

"It's important to note that while just about everyone thinks they know what the CSV 
file format is, there is actually no formal definition of the format and there are 
many subtle differences. Here's one description of a CSV file: 


  http://www.whatis.com/csvfile.htm

"

Source: http://dbi.symbolstone.org/cgi/summarydump?module=DBD::CSV

That whatis link is broken, see 
http://whatis.techtarget.com/definition/0,,sid9_gci213871,00.html

On several sites I encoutered the same (incomplete and vague) BNF definition, original 
source unknown:

<CSV_file> ::= { <CSV_line> }
<CSV_line> ::= <value> { "," <value> } <spaces_and_tabs> <CRLF>
<value> ::= <spaces_and_tabs>
        (
          { <any_text_except_quotas_and_commas_and_smth_else> }
        | <single_or_double_quote>
          <any_text_save_CRLF_with_corresponding_doubled_quotas>
          <the_same_quote>
        )

That's all I think... and there is some problem with this format:
different database systems have different definitions of the
term <any_text_except_quotas_and_commas_and_smth_else> :)

[Found, amongst others, on http://myfileformats.com/search.php?name=CSV]

Changed status again because of accidentel cross-update, and assigning to myself.

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

[2001-11-08 16:32:55] [EMAIL PROTECTED]

What output did you expect then from your example?

Derick

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

[2001-11-08 16:32:16] [EMAIL PROTECTED]

The CSV format prescribes that fields may be enclosed in double quotes, to make it 
possible to have the delimiter itself part of a field.

try google on CSV, to find a definition. If you find one, we'd appreciate it if you 
entered a link here, so we can make the documentation better.

Changing to documentation bug (indeed, the docs aren't clear about this)

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

[2001-11-08 16:22:46] [EMAIL PROTECTED]

How is this /not/ a bug?

It does the same thing indepentdent of delimiter.

If I have a CSV file that looks like
one,"two" three,four
one,two" three",four
one,two,three,four
one,two "three" four,five

and it gets read in as
('one', 'two', 'four')
('one',' two "three"', 'four')
('one', 'two', 'three', 'four')
('one', 'two "three" four', 'five')

That behavoir does not match the function definition of fgetcsv in the manual.  it is 
mishandling the data. 

"fgetcsv --  Gets line from file pointer and parse for CSV fields 

Description

    array fgetcsv (int fp, int length, string [delimiter])
 
Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSV 
format and returns an array containing the fields read. The field delimiter is a 
comma, unless you specify another delimiter with the optional third parameter. "

How can that possibly mean "strips off double quotes and removes subsequent data"?  
I'd expect it to split on the delimiter specified, and to file the resulting 
information into the array.


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

[2001-11-08 15:33:14] [EMAIL PROTECTED]

This is exactly what fgetcsv is for (interpreting the double quotes in CSV files). Use 
explode if you simply want to split on tabs.

No bug.

--Jeroen

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/?id=13950


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

Reply via email to