tags:

views:

32

answers:

2

I need to add columns to an existing csv file ,but i can't find any solution to the problem.I have used "\t" and chr(9) to create columns but no success so please help me by providing me the right solution if any one can

A: 

Could you try using \r\n instead of \n ?

Stephen
+4  A: 

Try this, and have a look at fgetcsv() and fputcsv() in the manual

<?php
$newCsvData = array();
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $data[] = 'New Column';
        $newCsvData[] = $data;
    }
    fclose($handle);
}

$handle = fopen('test.csv', 'w');

foreach ($newCsvData as $line) {
   fputcsv($handle, $line);
}

fclose($handle);

?> 
Phliplip