i have a small issue converting a csv file,
The file is converting, but is getting a Notice
Notice: Undefined offset: 2 in Notice: Undefined offset: 4 in
Also i need to group by $row[2] is this possible?
<?php
$tsvFile = new SplFileObject('file.csv');
$tsvFile->setFlags(SplFileObject::READ_CSV);
$tsvFile->setCsvControl("\t");
$file = fopen('file2.csv', 'w');
$header = array('col1', 'col2');
fputcsv($file, $header, ',', '"');
foreach ($tsvFile as $line => $row) {
if($line > 0) {
fputcsv($file, array($row[2], $row[4]), ',', '"');
}
}
fclose($file);
?>
Any help is appreciated.
isset()is usually what you need when referencing an array offset that might not be set. The explode on the tabs might be getting munged on some rows or something... missing tabs or what not.