Skip to content

Instantly share code, notes, and snippets.

@Padilo300
Created January 27, 2021 11:22
Show Gist options
  • Save Padilo300/dfb7d7c9decdda4b8e837b9012a4791e to your computer and use it in GitHub Desktop.
Save Padilo300/dfb7d7c9decdda4b8e837b9012a4791e to your computer and use it in GitHub Desktop.
csv generator
class CsvReader{
protected $file;
public function __construct($filePath) {
$this->file = fopen($filePath, 'r');
}
public function rows()
{
while (!feof($this->file)) {
$row = fgetcsv($this->file, 4096);
yield $row;
}
return;
}
}
$csv = new CsvReader("file.csv");
foreach ($csv->rows() as $row) {
// do
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment