I'm working on a script that will perform a few tasks
1) Load multiple text files each of which contains a line of numbers
2) In each text file remove white space and then add all lines
3) Append the contents of all of these text files to another text file
4) Add all numbers in the resulting text file
5) Save that resulting number as a new text file whose name is generated as the current date. (ie 2008-12-22.txt)
I've got some messy code below but would appreciate any assistance.
Code: Select all
<?php
$data1 = file('textfile1.txt');
$data1 = str_replace(' ','',$data1);
echo 'sum($data1) = ' . array_sum($data1) . "\n";
$sum = array_sum($data1) . "\n";
$data2 = file('textfile2.txt');
$data2 = str_replace(' ','',$data2);
echo 'sum($data2) = ' . array_sum($data2) . "\n";
$sum2 = array_sum($data2) . "\n";
$data3 = file('textfile3.txt');
$data3 = str_replace(' ','',$data3);
echo 'sum($data3) = ' . array_sum($data3) . "\n";
$sum3 = array_sum($data3) . "\n";
$fp = fopen('textmaster.txt', 'a');
fwrite($fp, $sum);
fwrite($fp, $sum2);
fwrite($fp, $sum3);
fclose($fp);
?>