File merge

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

File merge

Post 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.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

Something like...

Code: Select all

for ( $i = 0; $i < count($fc); ++$i )
{
    echo $fc[$i] . '.' . $fc1[$i] . '.' . $fc2[$i] . '<br>';
}
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

Post by slash85 »

Your a Genius!

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

Cheers,
Slash
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

No problem! Good luck with your script. :)
Post Reply