Re: rewrite one line in file

From: Date: Fri, 30 Mar 2001 01:18:28 +0000
Subject: Re: rewrite one line in file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-46206@lists.php.net to get a copy of this message
On Thu, 29 Mar 2001 23:35, Peter Van Dijck wrote: > How do I rewrite 1 line in a file? I got the filename and the > linenumber. i was playing around with fwrite but to find the line I had > to do all sorts of gymnastics, I'm sure there must be a more elegant > way... > thanks for any hints! > Peter In a nutshell, you load the file into an array containing one line per element of the array. You then work through the array until you find the line you want - if you know how many lines into the file it is you can of course directly reference the element (no_of_line -1 because the first array element is 0). Change the info you want. Write the changed array back to the file. Coding is left as an exercise for the student :-) -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#46206) next »