PHP reading a csv file effectively

后端 未结 2 2129
走了就别回头了
走了就别回头了 2021-02-10 11:18

There are a few ways to read CSV files with PHP. I used to use the explode function to put each line into an array and then explode commas and use trim

2条回答
  •  抹茶落季
    2021-02-10 11:58

    This converts the CSV into a nested array. Might be easier for you to deal with:

     0)
                    {
                        // This is a row in the CSV that needs to be stored in the return array
                        $csv_array[] = csv_entry_to_array($row);
                    }
    
                    $row_counter++;
                }
    
                // Close file handler
                fclose($handle);
            }
            else
            {
                // Input file: some error occured
                return array();
            }
    
            return $csv_array;
        }
    

提交回复
热议问题