php - How do I write on a file without clean it? -


how write on file without clean file using fwrite function? write skiping line using fwrite in text file.

$fp = fopen('somefile.txt', 'w');  fwrite($fp, "some text");   fwrite($fp,"more texto in line");  fclose($fp); 

set open mode "append" instead of "write" (see documentation fopen):

$fp = fopen('somefile.txt', 'a'); 

if on windows, may want consider using t flag denote file opening text file, proper line-ending character being used (\r\n instead of \n windows):

$fp = fopen('somefile.txt', 'at'); 

now, add text onto new lines, make sure use php_eol newline character character ensure right newline characters being written right oss:

fwrite($fp, php_eol . 'some text'); fwrite($fp, php_eol . 'more text on line'); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -