468,727 Members | 1,472 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

Copying a CSV file and changing a column of data

Hi,

I'm using php 4.4.4. I have a CSV file that contains columns "A" and
"B". What is the simplest way to create a second CSV file with the
values of column "A" copied into column "B"? The other columns in the
file can be left alone.

Thanks, - Dave

Apr 3 '07 #1
1 1320
la***********@zipmail.com wrote:
Hi,

I'm using php 4.4.4. I have a CSV file that contains columns "A" and
"B". What is the simplest way to create a second CSV file with the
values of column "A" copied into column "B"? The other columns in the
file can be left alone.

Thanks, - Dave
Read in the file contents line by line, explode() the lines using the
comma as the separator string, swap the resulting arrays' first two
cell's contents, join()/implode() the array items in a string with the
comma separator, write them to a new file, unlink the first, rename the
new one, done.

Something like that?
Best!
Sh.
Apr 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Joe Fallon | last post: by
2 posts views Thread by somequestion | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.