Forum Moderators: coopster

Message Too Old, No Replies

CSV? Everywhere!

Comma Separated Values?

         

anshul

5:36 am on Oct 29, 2005 (gmt 0)

10+ Year Member



Recently, I heard lot about CSV files.
I've worked (partly) on one script, that also uses CSV file.

I see, it's a XLS document..

I'm interested to know, how CSV relates to PHP, that much?

Most of us here know, to use tab-separated TXT files; we don't know how PHP deals/generates with XLS or DOC documents!

What experts say?

john_k

6:19 am on Oct 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSV isn't an Excel (XLS) format. Like tab-separated text files, it is simply a standard format that can be used to exchange data. Also like tab-separated files, data exchange is generally the only reason it is used.

I think there may be some type of formal set of specs for the format. But generally, you just separate all field values with a comma. Text fields should be enclosed in quotation marks and numeric fields shouldn't. You can generally get away without the quotation marks in the text fields as long as they don't contain commas. I don't recall how you escape quotation marks within the text itself.

The first row can contain column/field names. There may also be a provision to define an alternate delimiter (commas being the default).

If you install Excel on your computer, it will register itself as the default application to open CSV files. But it is not an Excel proprietary file format.

ergophobe

3:53 pm on Oct 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP has built-in utilities for dealing with CSV files (fputcsv, fgetcsv) but it has nothing built-in for parsing Excel or Word files.

You could perhaps hack something out or some script may exist, but if I had to do that as part of a web application, I would probably want to be on a windows server where I could use Visual Basic for Applications and make calls from my script to the VBA scripts. I can hack out some VBA, but I have no idea how to integrate that on the web server, but I bet they do over in the Microsoft .NET and ASP [webmasterworld.com] forum.