I am trying to recreate a csv file based on another csv source file. I am trying to skip the whole row when that row has a specific word "WORDO". For now I'm only able to replace the data which has "WORDO" by some empty string (""). However I would like to skip the whole row when a match is found, . For now the $keepColumns array still keeps data[1] ( empty, or not) I would like to skip the whole row when "WORDO" is inside $data[1]
<?php
$finalArray = array();
$newFinalData = "new_csv.csv";
if (($finalData = fopen("mycsv.csv", "r")) !== FALSE)
{
$newfile = fopen($newFinalData, 'w');
while (($data = fgetcsv($finalData, 999999, ",",'"')) !== FALSE)
{
//If the 1st column has WORDO as text, ideally skip the whole row
if( substr( $data[1], 0, 5 ) === "WORDO" ) {
$data[1] = "";
}
$keepColumns = array(
$data[0],
$data[1],
$data[2],
$data[5]
);
fputcsv($newfile, $keepColumns, ";",'"');
}
fclose($finalData);
fclose($newfile);
}
?>
continue;