> I have 40 text files.. each files have 1 colomn of a data. I want to write a
> script to merge them like
> 
> datafrom1;datafrom2;datafrom3;....datafrom40
> 
> how can I do that?

Assuming that by "1 column" you mean each file has data, then a new line
character, then data, then a new line character, etc., you could read each
file into a variable:

$data1 = "";
$file = "(path to the file)";
$fp = fopen($file, "r");
if ($fp) {
    while (!feof($fp)) {
        $data1 .= fread($fp, 1024);
    }
}
fclose($fp);

Then make each file an array by exploding on the new line character:

$records1 = explode("\n", trim($data1));

Find the size of each array as you make them (if they have different sizes,
track the largest size value somehow):

$num_records = count($records1);

Then concatenate:

for ($x = 0; $x < $num_records; $x++) {
    $merged_files = $records1[$x] . $records2[$x] . (etc) . $records40[$x];
}

If you need the data separated with semicolons, add them when concatenating.

HTH

--
Lowell Allen


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to