472,146 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 1435
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
reply views Thread by Saiars | last post: by

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.