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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -