swamp Posted February 23, 2009 Share Posted February 23, 2009 Hi, I need to write to a txt file but leave the last line intact. I'm using fwrite($handle, $content) but I need to keep the last line in my txt file which is "--Document End--" For example if I write "new line of text" to "test.txt" I need it to show up as (old content) new line of text --Document End-- Any hints? Thanks Quote Link to comment Share on other sites More sharing options...
sloth456 Posted February 23, 2009 Share Posted February 23, 2009 yeah, just make sure when you update the file that you first remove the old --Document End-- and post a new --Document End-- at the bottom. Is that a satisfactory solution? Quote Link to comment Share on other sites More sharing options...
swamp Posted February 23, 2009 Author Share Posted February 23, 2009 ... I know the logic of it, I'm just not sure about the code, any hints on how to do that? Quote Link to comment Share on other sites More sharing options...
sloth456 Posted February 23, 2009 Share Posted February 23, 2009 Do an fopen statement and put what you got into a string called $text. Then do a str_replace to replace --Document End-- with nothing. Then something like this $newtext=$text.$newline."--Document End--"; Then rewrite the old file with $newtext. Quote Link to comment Share on other sites More sharing options...
swamp Posted February 23, 2009 Author Share Posted February 23, 2009 Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.