Simple fwrite question
| From: | Hartley, Matt | Date: | Tue, 23 Dec 2003 15:27:30 +0000 |
| Subject: | Simple fwrite question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173244@lists.php.net to get a copy of this message | ||
I am trying to have a counter in a file. With what I have below I get in
the $counterfile
0 + 01 = 01
01 + 01 = 012
012 + 01 = 01213
[snip]
/* Add "1" to the counter */
$counter = ($counter + '01');
/* Verify counter file is writable */
if (is_writable($counterfile)); /* { */
if (!$handle = fopen($counterfile, 'a')) {
print "Cannot open file ($counterfile)";
exit;
}
/* Write to our counter file. */
if (!fwrite($handle, $counter)) {
print "Cannot write to file ($counterfile)";
exit;
}
fclose($handle);
[/snip]
How do I overwrite the existing value with my new value instead of it adding
on after the past values?
My other dilemma is,
this counter decides what line to display in a sequence from a separate file
what command can I use to tell it when $counter is @ the last line in my
"tips" file to reset to zero
thanks
Matt