[PHP] fputs / fwrites
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 .. it seems that there should be a way of doing this without having to open and close the file twice. I've tried: $cfile = fopen(lcnt.txt, 'r+'); $lcnt = fgets($cfile,10); This results in $lcnt having a value of 1 (loaded from value within 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 ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fputs / fwrites
On Wednesday 05 February 2003 15:00, Lee Herron wrote: 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 .. it seems that there should be a way of doing this without having to open and close the file twice. I've tried: $cfile = fopen(lcnt.txt, 'r+'); $lcnt = fgets($cfile,10); This results in $lcnt having a value of 1 (loaded from value within 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 ... RTFM -- rewind(), fseek(). -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* There is no act of treachery or mean-ness of which a political party is not capable; for in politics there is no honour. -- Benjamin Disraeli, Vivian Grey */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fputs / fwrites ?
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fputs / fwrites ?
Please, don't hijack(*) the threads. (*) Hijack a thread - replying to an email from the usergroup modifying its subject and body making it look like a new post. Emails have also the in-reply-to headers which make the threads visualize in mail clients as the follow ups, although was intended as a new thread. -- Maxim Maletsky [EMAIL PROTECTED] On Fri, 31 Jan 2003 23:41:12 -0600 Lee Herron [EMAIL PROTECTED] wrote: 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php