Last active
January 3, 2019 09:34
-
-
Save Padilo300/067674787695ee61768cd2abef545646 to your computer and use it in GitHub Desktop.
PHP parce BIG SCV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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