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?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.