Xabache Posted February 23, 2012 Share Posted February 23, 2012 .txt file. 10 numbers in 10 rows.question the first: using php how do i read from any one specific line?question the second: using php how do i write a value over any specific line? Link to comment Share on other sites More sharing options...
boen_robot Posted February 23, 2012 Share Posted February 23, 2012 1. The easiest way is to use the file() function, and then target the line by the index of the generated array. You could also instead call fgets() multiple times until you reach the line you want to read from.2. Similarly to reading, you could use file() to get an array of lines, and then implode it and overwrite the whole file. A more RAM efficient solution (but more HDD demanding one) is to create a new file, use copy all lines up until the one you want to overwrite, write it, and copy the rest. If you want to just insert data on a line (and not replace a line), you can skip the extra file, and just use fgets() until you reach the line, and use fwrite() to write to the line. This is both HDD and RAM efficient (compared to file(), which is not RAM efficient, as it loads the whole file into an array). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.