I am trying to remove unnecessary column from my csv. What i do is read from current csv and use fputcsv to produce a new one. However, the data is mess up because fputcsv add extra blank column just before $data[21]
. Below is my code
$file_path = 'test.csv';
$file_output = 'new.csv';
if (file_exists($file_path) && filesize($file_path) > 0) {
if (false !== ($read_file = fopen($file_path, 'r'))) {
$output_file = fopen($file_output, 'w');
while (false !== ($data = fgetcsv($read_file))) {
$outputData = array($data[1], $data[6], $data[19], $data[20],
$data[21]);
fputcsv($output_file, $outputData);
}
}
fclose($read_file);
fclose($output_file);
}