fgetcsv delimiters

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have an xls worksheet I wish to export as a text or csv file to import
with fgetcsv()

The 'save as' function on excell lets me save as a comma separated value or
tab delimited text files.
Trouble is, some of my cells already have commas in them, so a tab or
something else would be better.
In the delimiter option of fgcsv(), can you specify a tab and how?
My other option (but a bit of a chore) is to copy and paste the xls data
into word, then replace all the tabs with something like ; that dosn't
appear in the cells.


Re: fgetcsv delimiters

Stephen Preston wrote:
Quoted text here. Click to load it

So go ahead and do it; there shouldn't be any problems...

Quoted text here. Click to load it

Doesn't matter; Excel encloses fields with commas in them in double
duotes, like this:

A simple field,"A field with a comma (,) in it",Another simple field

fgetcsv() understands this as well...

Quoted text here. Click to load it

This is a matter of opinion... :)

Quoted text here. Click to load it

You can if you want to:

fgetcsv($handle, 10240, "\t");

Note that since a custom delimiter is the third argument, the second
argument (the maximum length of a CSV string) must be specified...

For more information, see documentation on fgetcsv():



Re: fgetcsv delimiters

Stephen Preston:

Quoted text here. Click to load it

  No, that doesn't follow.  You can hide your delimiter (commas by
default) by double quoting them (double quotes by default, but any
character you set the fourth argument to).

Quoted text here. Click to load it

  \t or however you insert tabs (got a tab key?).

Quoted text here. Click to load it

  Well, I was about to say that TSV has the advantage that it boasts
its own registered MIME type, text/tab-separated-values; but lo and
behold text/csv was registered in October 2005.



Site Timeline