Skip to content

Instantly share code, notes, and snippets.

@rlfrahm
Last active August 29, 2015 14:22
Show Gist options
  • Save rlfrahm/a95616de8eb63c9761aa to your computer and use it in GitHub Desktop.
Save rlfrahm/a95616de8eb63c9761aa to your computer and use it in GitHub Desktop.
How to iterate through a CSV file using PHP
// Open the file
$file = fopen($uri,'r');
// If the first line is a header, uncomment the following..
// $header = fgetcsv($file);
// Iterate through each row of the file
while(!feof($file)) {
// Read in the row
// $row will be an array of values that correspond to
// the columns in the row, example:
// array (
// [0] => 'column_1_value',
// [1] => 'column_2_value',
// [n] => 'column_n_value',
// )
$row = fgetcsv($file);
}
// Close the file
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment