Copying a CSV file and changing a column of data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    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

  • Schraalhans Keukenmeester

    #2
    Re: Copying a CSV file and changing a column of data

    laredotornado@z ipmail.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.

    Comment

    Working...