title: PHP Skip First Line Of CSV If It Contains Specific Header Info
body: <p>I need to check the first line of a csv file to see if it contains the headers for columns (number, name, amount). If the first line contains these headers then exit the file or add number, name, amount if the first line does not contain this info.</p>
  
  <p>I was trying to check to see if the first column, first row contains a number which would mean no headers. </p>
  
  <p>Heres the code I was using. And thanks again for all your help.</p>
  
  <pre><code>$rows = $phones = [];
  if (($handle = fopen($file_tmp, "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      list($phone, $name, $amount) = $data;
      if(!($data = fgetcsv($handle))) {
  return;    //most likely empty file
  }
      if(!is_numeric($data[0])) {
          fputcsv($handle, array('number', 'name', 'amount'));
      }
  
      $phone = str_replace(['(',')','-'], '', $phone);
      $amount = str_replace(['$'], "", $amount);
      $amount = sprintf('$%.2f', $amount);
  
  
       // track unique phone numbers here
      if (isset($phones[$phone])) {
          // it's a duplicate so just ignore the entire row
          continue;
      }
      // otherwise it's a new phone number so store it
      $phones[$phone] = true;
      $rows[] = [$phone, $name, $amount];
      // or output directly
      //echo "$phone | $name | $amount";
      }
      fclose($handle);
  }    
  </code></pre>