Jump to content

write to a specific line


Xabache

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...