Page 1 of 1

append new content in a file from new line

Posted: Sat May 24, 2008 6:47 am
by vb_123
how to append new content in a file ??for example i have a file welcome.txt and i have some content in it lets say "hello world"...........now what i want is to append some more content in this existing file such that the new content comes in a new line........ like
hello world
welcome

thanks in advance

Re: append new content in a file from new line

Posted: Sat May 24, 2008 6:52 am
by VladSun
Open it in "append" mode.

Code: Select all

$fh = fopen('test.txt', 'a');

Re: append new content in a file from new line

Posted: Sat May 24, 2008 6:55 am
by vb_123
i have already opened it in a append mode the content is getting appended but not from a new line.thats the main problem??

Re: append new content in a file from new line

Posted: Sat May 24, 2008 7:03 am
by VladSun
Maybe because you have a "\n" caharacter when you write the string to the file.
Use trim() on the string before writing it.