I have a .CSV file with static column names. I receive it daily so i have to automatically edit it on a daily base.
On the first line are the row names for example: row1;row2;row3,row4,row5
for example when i want to unset "row2" and "row4".
How can i unset multiple rows based on a name?
I found a some tutorials about deleting lines or rows based on a row position but nothing that helps me completely.
This is what is have now:
$inFile = 'original.csv';
$outFile = 'edited.csv';
$delimiter = ';';
$enclosure = '"';
$read = fopen($inFile, 'r');
$write = fopen($outFile, 'w');
if ($write && $read) {
while (($data = fgetcsv($read)) !== FALSE) {
// how to unset multiple row names
fputcsv($write, $data, $delimiter, $enclosure);
}
}
fclose($write);
fclose($read);
Also, do i need to use the delimiter and enclosure when i fopen the original file?
if (row doesn't contain what I"m deleting) { output row }file_get_contents(),file_put_contents(),explode(),implode(), andif/thenlogic, not to mention loops.