473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

fgetcsv delimiters

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.

thanks
Mar 11 '06 #1
2 6221
NC
Stephen Preston wrote:

I have an xls worksheet I wish to export as a text or csv file
to import with fgetcsv()
So go ahead and do it; there shouldn't be any problems...
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
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...
a tab or something else would be better.
This is a matter of opinion... :)
In the delimiter option of fgcsv(), can you specify a tab


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():

http://www.php.net/fgetcsv

Cheers,
NC

Mar 11 '06 #2
Stephen Preston:
Trouble is, some of my cells already have commas in them, so a tab or
something else would be better.
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).
In the delimiter option of fgcsv(), can you specify a tab and how?
\t or however you insert tabs (got a tab key?).
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.


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.

http://www.ietf.org/rfc/rfc4180.txt

--
Jock

Mar 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe Randstein | last post by:
Hi! I get CSV-data from a post-request. How can I work on that? Currently I save the data to a temp-file, then read it back with fgetcsv and then delete the temp-file. That works, but I don't...
1
by: Jonaed | last post by:
This is my code: $handle = fopen ($file, "r"); $c = 1; while (($values_list = fgetcsv ($handle, 1000, ',', '"')) !== FALSE) { echo $c . "<br>\n"; $c = $c +...
0
by: tjonsek | last post by:
I am working with directories in PHP for the first time. I have code that I've changed multiple times to try different things. I would think this is pretty standard fare so I'm not sure why I can't...
0
by: et | last post by:
fgetcsv() do unwanted "left trim" on fields started with locale characters (code page win-1250). Problem persist only if local character is first character in field for example, let say that C...
5
by: mantrid | last post by:
I am using fopen() and fgetcsv() to open an excel file and extract data for upload to mysql database. The doesnt seem to be a parameter in either of these functions for ommitting the first row of...
6
m6s
by: m6s | last post by:
1. After hours of researching, I used these snippets : void Object::TokenizeLines(const string& str, vector<string>& tokens, const string& delimiters) // Skip delimiters at beginning....
5
by: gpaps87 | last post by:
hi, i wanted to know whether we can use strtok command to mark delimiters as tokens as well.In Java,we have a command: StringTokennizer(String str, String delimiters, boolean delimAsToken) ...
3
by: jrrdnx | last post by:
I have a form set up to allow someone to upload a .csv and populate its data into a database using the fgetcsv() function. All of the code works fine because everything in the .csv file is populated...
2
code green
by: code green | last post by:
I am trying to skip empty rows in a csv file The manual states But none of these tests seem to work. Anybody know why while(($data = fgetcsv($this->handle)) !== false) { ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.