title: PHP fgetcsv() - find number of columns
body: <p>I'm trying to determine how many columns a csv file has.</p>
  
  <p>Here's my script, which is only utilizing the first column, but I'm running slightly blind. I want to place a variable that limits the column count.  (since I may make a mistake and add a column, or even miss a column)</p>
  
  <pre><code>&lt;?php
  $allowedColNum=5;
  $batchcount=0;
  $file = fopen($file_name, "r"); 
  while ($line = fgetcsv($file)){
   /* I want to stop the loop if the $allowedColNum is not correct */                 
    $col = $line[0]; 
    echo $batchcount++.". ".$col."\n";
  }
  
  fclose($file);
  ?&gt;
  </code></pre>
  
  <p>I'm sure it's one of those easy easy things that I'm not getting.</p>