In my code I'm reading csv file with fgetcsv
function
while($line = fgetcsv($handle, 4096)){
.....
}
How can check when the $line
is empty, I mean $line = ',,,,,,,,'
?
note: I'm not always know the number of columns.
In my code I'm reading csv file with fgetcsv
function
while($line = fgetcsv($handle, 4096)){
.....
}
How can check when the $line
is empty, I mean $line = ',,,,,,,,'
?
note: I'm not always know the number of columns.
One way to do it would be:
if (str_replace(array(',', ' '), '', $line) != '') {
// do something
}
Basically, it will compare the line after you remove all comma's and spaces from the string.
You can take the contents of file in an array and check which index has empty value. like this -
$handle = fopen("file.csv","r");
$data = fgetcsv($handle,",");
while($data = fgetcsv($handle))
{
$array = explode(",",$data[0]);
print_r($array);
}
fclose($handle);