How can PHP code be modified to write strings on separate lines in a file?

To write strings on separate lines in a file using PHP, you can append a newline character "\n" at the end of each string before writing it to the file. This will ensure that each string is written on a new line in the file.

<?php

// Strings to write to the file
$string1 = "Hello";
$string2 = "World";

// Open the file in append mode
$file = fopen("output.txt", "a");

// Write strings on separate lines
fwrite($file, $string1 . "\n");
fwrite($file, $string2 . "\n");

// Close the file
fclose($file);

?>