Re: Writting to files.?
| From: | James Bartlett | Date: | Thu, 05 Jul 2001 23:12:57 +0000 |
| Subject: | Re: Writting to files.? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-56401@lists.php.net to get a copy of this message | ||
Thanks for the response so far...
I'm still not sure on how to get the code to start on a new line in the file (yes they are text
files). Say I wrote variable1 to line one how do I get it to write the next variable to line two?
Thanks
----- Original Message -----
From: Don Read
To: James Bartlett
Cc: php-general@lists.php.net
Sent: Thursday, July 05, 2001 6:40 PM
Subject: RE: [PHP] Writting to files.?
On 05-Jul-01 James Bartlett wrote:
> Hi,
>
> Anyone know how I can write and read to different lines in a file rather
> than just adding to the text already on the first line of the file?
>
> Thanks
>
Assuming you're talking about text files:
A. suck the whole thing up in memory, change it there, write it back out.
B. open a temp, copy till the line of interest, write your change,
copy remainder. mv/cp the temp to the original.
C. read to line of interest, ftell(), suck remainder into memory.
ftruncate(), fseek(), write your changes, write out the remainder.
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.