Page 1 of 1

File merge

Posted: Wed Feb 28, 2007 3:14 pm
by slash85
Hi,

I'm trying to merge 3 files into one by doing the below:

Code: Select all

<?php

$fc=file("first.txt");
$fc1=file("second.txt");
$fc2=file("date.txt");

echo "$fc[0].$fc1[0].$fc2[0]<br>";
echo "$fc[1].$fc1[1].$fc2[1]<br>";
echo "$fc[2].$fc1[2].$fc2[2]<br>";

?>
This would be fine if the files only contained 3 lines, but the file will often contain more lines and i was thinking of using a foreach but unsure how to do it so that it echo's in this format:

Joe, Bloggs, 28/02/07
John, Smith, 26/02/07

Any idea's?

Thanks again,

Slash.

Posted: Wed Feb 28, 2007 3:19 pm
by Nathaniel
Something like...

Code: Select all

for ( $i = 0; $i < count($fc); ++$i )
{
    echo $fc[$i] . '.' . $fc1[$i] . '.' . $fc2[$i] . '<br>';
}

Posted: Wed Feb 28, 2007 3:23 pm
by slash85
Your a Genius!

Thanks alot for the help, exactly what i was after.

Cheers,
Slash

Posted: Wed Feb 28, 2007 3:25 pm
by Nathaniel
No problem! Good luck with your script. :)