Try as in the PHP manual:
while( ( $keys = fgetcsv( $fp, 0, "\t" ) ) !== FALSE ) {
Also, make sure your input csv has a clean end of file.
Question
while ($keys = fgetcsv($fp, 0, "\t")) {
if ($c == 0) {
$headers = $keys;
} else {
$rows[] = $keys;
//var_dump($keys);
}
$c ++;
}
fclose($fp);
echo count($rows);
If I echo the $count
it works fine(shows the proper count), even if I dump the keys (commented line) it echoes as expected, but nothing happens after the loop ends. at around 9154 rows;
These lines below don't work and the script execution stops without any apparent error.
fclose($fp);
echo count($rows);
Solution
Try as in the PHP manual:
while( ( $keys = fgetcsv( $fp, 0, "\t" ) ) !== FALSE ) {
Also, make sure your input csv has a clean end of file.
OTHER TIPS
Try this and tell us what happens:
// make sure we see all errors
error_reporting(-1);
ini_set('display_errors', true);
// read the entire file into an array, one element per row
$rows = array();
while($fields = fgetcsv($fp, 0, "\t")) {
$rows[] = $fields;
}
fclose($fp);
// handle empty CSV case
if(count($rows) == 0) {
die('CSV is empty');
}
$headers = $rows[0];