Last active
December 25, 2015 02:19
-
-
Save kcassam/6901793 to your computer and use it in GitHub Desktop.
Aggregate multiple files in one (Quick and dirty)
This file contains 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 | |
$pathname = __DIR__."/filestoaggregate"; | |
$tab[0] = array("firstname","lastname","gender","email","code","newsletter","variable","giftcode"); | |
$separator = "="; | |
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathname), RecursiveIteratorIterator::SELF_FIRST); | |
$i = 1; | |
foreach($iterator as $item) { | |
$j = 0; | |
if (in_array(basename($item), array(".", "..", ".DS_Store"))) { | |
continue; | |
} | |
$fic=fopen($item, "r"); | |
while(!feof($fic)) | |
{ | |
$ligne= fgets($fic,1024); | |
$ligne = str_replace(CHR(13).CHR(10),"",$ligne); | |
$pos = strpos($ligne, "user"); | |
if($pos == false){ | |
$array = explode($separator, $ligne); | |
$chaine = str_replace('"', '', $array[1]); | |
$tab[$i][$j] = $chaine; | |
} | |
$j++; | |
} | |
$i++; | |
fclose($fic) ; | |
} | |
$fp = fopen('output.csv', 'w'); | |
foreach ($tab as $fields) { | |
fputcsv($fp, $fields); | |
} | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment