adding a date column
Posted: Mon Dec 22, 2008 10:50 am
~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.
Here's my existing code
~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.
Here's my existing cod
Code: Select all
<?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)
?>~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: