I am trying to determine how many columns a csv file has.
Here is my script that uses only the first column, but I'm a little blind. I want to put a variable that limits the number of columns. (since I can make a mistake, add a column or even skip a column)
<?php
$allowedColNum=5;
$batchcount=0;
$file = fopen($file_name, "r");
while ($line = fgetcsv($file)){
$col = $line[0];
echo $batchcount++.". ".$col."\n";
}
fclose($file);
?>
I'm sure this is one of those light easy things that I don’t get.
source
share