Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how can we merge csv file in laravel

<?php
function joinFiles(array $files, $result) {
    if(!is_array($files)) {
        throw new Exception('`$files` must be an array');
    }

    $wH = fopen($result, "w+");

    foreach($files as $file) {
        $fh = fopen($file, "r");
        while(!feof($fh)) {
            fwrite($wH, fgets($fh));
        }
        fclose($fh);
        unset($fh);
        fwrite($wH, "
"); //usually last line doesn't have a newline
    }
    fclose($wH);
    unset($wH);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #merge #csv #file #laravel
ADD COMMENT
Topic
Name
9+8 =