When write a string output to a file with file_put_contents function with FILE_APPEND flag in PHP, the text will be appended to the end of the line, without any line break.
There are several ways to force file_put_contents function to insert a new line or end of line (EOL) character to indicate the line ending, and allow the start of new line for the new data.
Here’s a few way to force the end of the line and start a new line when output to a file on PHP scripts.
Method 1: PHP_EOL PHP End of Line
$file = 'techjourney.txt'; $text = PHP_EOL . "Tech Journey"; file_put_contents($file, $text, FILE_APPEND);
Method 1: \r\n
$file = 'techjourney.txt'; $text = "Tech Journey\r\n"; file_put_contents($file, $text, FILE_APPEND);