fgetcsv 循环后没有任何反应.尝试从 Amazon mws API 保存制表符分隔报表中的数据


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);

如果我回显$count它工作正常(显示正确的计数),即使我转储键(注释行),它也会按预期回显,但循环结束后没有任何反应。 大约 9154 行;

下面的这些行不起作用,脚本执行停止,没有任何明显的错误。

fclose($fp);
echo count($rows);
尝试像

PHP 手册中一样:

while( ( $keys = fgetcsv( $fp, 0, "'t" ) ) !== FALSE ) {

此外,请确保您输入的 csv 具有干净的文件结尾。

试试这个,告诉我们会发生什么:

// 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];