0

I have a csv file with the following data:

DATA1-1 DATA1-2 DATA1-3
DATA2-1 DATA2-2 DATA2-3
DATA3-1 DATA3-2 DATA3-3

I need to append more data to the file so it will look like this:

DATA1-1 DATA1-2 DATA1-3 DATA1-4 DATA1-5
DATA2-1 DATA2-2 DATA2-3 AAAAAAA BBBBBBB
DATA3-1 DATA3-2 DATA3-3 AAAAAAA BBBBBBB

I have tried fgetcsv() and fputcsv() but could not figure it out. Whenever I try to write anything to the first line, my data always goes to the second line. This needs to be done in php. Any help?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by priebd1
0

what i would do is:

drop the file into and array
$temp = file('path/yourfilename.csv');

add the needed data

foreach($temp as $key => $value)
    $temp[$key] = $value.";".$data1.";".$data2."\r\n";

rewrite the file with new data

$fp = fopen('path/yourfilename.csv', 'w');//not append, overwrite file
        foreach($temp as $key => $value)
            fwrite('$fp', $value);

        fclose($fp);

now maybe some guru have a better answer or can correct me if im wrong
im still a jr, trying to give back

Dark

0

Thanks Dark for your reply...I will try this and post back

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.