3
I have the following csv file and would like to remove the blank lines
For example
File . csv
"C","C","X","123","asdsd","'232","'323","","323","23","4","dsa","dsad","dsa","ds","dsad","sdad,","24","0","11","4,2","fdf","","k","502","00","0035"," RAL","dgdf","R","12345","098765","321324",""
"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
"C","C","X","123","asdsd","'232","'323","","323","23","4","dsa","dsad","dsa","ds","dsad","sdad,","24","0","11","4,2","fdf","","k","502","00","0035"," GL","dgdf","R","12345","098765","321324",""
"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
"C","C","X","123","asdsd","'232","'323","","323","23","4","dsa","dsad","dsa","ds","dsad","sdad,","24","0","11","4,2","fdf","","k","502","00","0035"," G","dgdf","R","12345","098765","321324",""
"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
"C","C","X","123","asdsd","'232","'323","","323","23","4","dsa","dsad","dsa","ds","dsad","sdad,","24","0","11","4,2","fdf","","k","502","00","0035"," ERL","dgdf","R","12345","098765","321324",""
"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
And I wanted to remove the blank lines.
"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
I wrote this code but it’s not working someone can help me ?
$or = fopen("output.csv", 'r');
$nv = fopen("novo.csv", 'a+');
$lines = fgetcsv($or, 5000, ",",'"');
foreach ($lines as $line) {
$csv = str_getcsv($line);
if (count(array_filter($csv)) != 0) {
fputcsv($nv, $line ,",",'"');
}
}
fclose($or);
fclose($nv);
}
Which error your code returns?
– durtto