Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Padilo300/067674787695ee61768cd2abef545646 to your computer and use it in GitHub Desktop.
Save Padilo300/067674787695ee61768cd2abef545646 to your computer and use it in GitHub Desktop.
PHP parce BIG SCV file
<?php
class CsvIterator {
protected $file;
public function __construct($file) {
$this->file = fopen($file, 'r');
}
public function parse() {
$headers = array_map('trim', fgetcsv($this->file, 4096));
while (!feof($this->file)) {
$row = array_map('trim', (array)fgetcsv($this->file, 4096));
if (count($headers) !== count($row)) {
continue;
}
$row = array_combine($headers, $row);
yield $row;
}
return;
}
}
$Filter = new CsvIterator(__DIR__ . '/lead.csv');
echo "<pre>";
// пример
foreach ($Filter->parse($pathBest) as $row) {
var_dump($row);
}
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment