Using the code posted earlier as a start:
Code:
<?php
// bring each file into an array
$f1 = file( "testfile1.txt" );
$f2 = file( "testfile2.txt" );
// get len of each array
$max = count( $f1 );
$chkmax= count($f2);
// use shorter array as maximum value to avoind errors
if($chkmax<$max){$max=$chkmax;}
// create a new array. You could also open a file to write to instead
$new = array();
$fp=fopen('testfile3.txt','w');
// do the loop properly.
for( $i = 0; $i <= $max; $i++ ){
// build the new array properly
$new[$i] = trim($f1[$i]) . trim($f2[$i]) . "\n";
echo $new[$i] . '<br>';
// if you are writing to a new file you can do it here if you wanted
// check to make sure the file opened before writing
if ($fp)
{
// write to the file
fwrite($fp,$new[$i]);
}
}
// Print out the rows of the array using print_r or
// if you are writing to a new file you could do it here if you wanted to too
// print_r($new);
if ($fp)
{
// make sure to close the file if you are writing one
fclose($fp);
}
?>
Working model at
http://sigamatic.com/newtest/testit.php
testfile 1 at
http://sigamatic.com/newtest/testfile1.txt
testfile 2 at
http://sigamatic.com/newtest/testfile2.txt
Ouptut file at
http://sigamatic.com/newtest/testfile3.txt
Have fun
