Search code examples
phpfgetcsvfileparsing

Nothing happening after the fgetcsv loop. Trying to save data from a tab delimitted report from amazon mws api


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.