How can PHP developers ensure that user input is properly formatted and displayed in separate lines when saved to a text file?

When saving user input to a text file in PHP, developers can ensure proper formatting and display in separate lines by using the PHP_EOL constant to represent the end of a line. This constant automatically inserts the appropriate line ending based on the operating system. By concatenating PHP_EOL to each user input before saving it to the text file, developers can ensure that each input is displayed on a separate line.

$userInput = "User input here";
$file = fopen("textfile.txt", "a");
fwrite($file, $userInput . PHP_EOL);
fclose($file);