fputs / fwrites ?
| From: | Lee Herron | Date: | Sat, 01 Feb 2003 05:41:12 +0000 |
| Subject: | fputs / fwrites ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133852@lists.php.net to get a copy of this message | ||
Okay, so I want to open a file, get a small number from it (less than 3
digits) then overwrite a new number (incremented the original by 1) and
close the file.
The goal is to do this in the fastest way possible .. I don't like having to
open the file more than once to do this.
I've tried:
$cfile = fopen("lcnt.txt", 'r+');
$lcnt = fgets($cfile,10);
This results in $lcnt having a value of 1 (from value in text file)
Now, if I increment it:
$nc = $lcnt+1;
then write it back to the file:
$nul = fwrite($cfile, $nc);
It writes starting at where the last read left off -- I want to start at
zero offset so to overwrite the existing value. I can't find a method for
resetting the offset pointer without having to close the file and reopen it
with w+
There must be a simpler way to do this and I have a mental block.