What are some best practices for writing multi-line content to a file using PHP fwrite?

When writing multi-line content to a file using PHP fwrite, it's important to properly format the content with newline characters (\n) to separate each line. This ensures that each line is written on a new line in the file. Additionally, it's best practice to open the file in "a" mode (append) to avoid overwriting existing content.

$content = "Line 1\nLine 2\nLine 3";
$file = fopen("file.txt", "a");
fwrite($file, $content);
fclose($file);