Topic: How do I retrieve the last line of a file? Pages that link to <a href="https://ozoneasylum.com/backlink?for=31469" title="Pages that link to Topic: How do I retrieve the last line of a file?" rel="nofollow" >Topic: How do I retrieve the last line of a file?\

 
Author Thread
ruffy
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2008

IP logged posted posted 11-06-2009 17:18 Edit Quote

I go through a file using
WHILE(! feof()), during which
I write to a file ($wfile).

Once done, I need to make a
change in the last line of the output
file.

How do I do this?

argo_navis
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2008

IP logged posted posted 01-13-2010 14:22 Edit Quote

If you want to append a new line, you simply open the file in append mode, $fh = fopen($myFile, 'a');
Otherwise, you could load the file with file_get_contents, explode it using a "\n" separator (end of line character), edit the last entry in your array, then write it back.

File access is fast enough so while this is not perfect, it will get the job done.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu