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
Post a Comment