Re: Editing files by line

From: Date: Thu, 11 Jul 2002 04:21:27 +0000
Subject: Re: Editing files by line
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-107014@lists.php.net to get a copy of this message
That's what I was talking about :). I wish there was something built in that would just let me append a file where I want, that would make things a little easier. Oh well, thanks a lot for the help that makes sense (and I think it works). "Martin Towell" <martin.towell@world.net> wrote in message news:6416776FCC55D511BC4E0090274EFEF508A5FD@EXCHANGE... > I dodn't know of any single function that does what you want, but you can do > this: > > $contents = file($filename); // each line has it's own array position > $contents[$line] = $newline; > $content = implode("\n", $contents); > $f = fopen($filename, "w"); > fputs($f, $content); > fclose($f); > > > (not tested, but should work as is) some error checking would also be > good.... :) > > -----Original Message----- > From: Chris Earle [mailto:chris@earleweb.com] > Sent: Thursday, July 11, 2002 2:10 PM > To: php-general@lists.php.net > Subject: [PHP] Editing files by line > > > I was wondering if there was a function that would allow me to "jump" to a > certain line if a file and then write from there? I'm searching php.net > without any luck :(. > > Also, if there is not specific function, is there a trick that gives the > same effect (without reading the entire file line by line, then writing to > it where I need to, then replacing the file)? > > Thanks in advance (hopefully :)). > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#107014) next »