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!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
I currently have a script that adds numbers from multiple files and then outputs the sum (a single number like 28449358) to a new text file named as the current date (ie 2008-12-22). Although this is working I'd like to change the code so that the sum is appended to a file called total.txt. However, in addition to the number there needs to be a date stamp separated by a ";" (ie 2008-12-22;28449358). This would be appended to each day. Btw, Im using php4.
<?php
// Make an array of the filenames to sum
$fileNames = array('textfile.txt', 'textfile2.txt', 'textfile3.txt');
// Open the file and zero out the net sum
$fp = fopen('textmaster.txt', 'a');
$netSum = 0;
// Add the numbers and append to the file
foreach($fileNames as $fileName) {
$content = str_replace(' ', '', file($fileName));
$sum = array_sum($content);
echo 'Sum of "' . $fileName . ': ' . $sum;
$netSum += $sum;
fwrite($fp, $sum);
}
// Clean up
fclose($fp);
// Create the day file
$fw = fopen(date('Y-n-j') ';');
fwrite($fw, $netSum);
fclose($fw)
?>
e
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
To elaborate, my problem is that currently my output is a text file whose filename will be the current date and whose contents will be a single number (sum from script).
What I want is the output to be saved (appended) to an existing file (total.txt) and instead of simply providing the number, to also include a date stamp. So each day the output would be (2008-12-22;238794)
Over a series of days, the resulting total.txt would look like: