How can a separator be added at the end of each line in a text file created using PHP?

To add a separator at the end of each line in a text file created using PHP, you can simply append the separator to each line before writing it to the file. This can be done by concatenating the separator to the end of each line before writing it using the fwrite() function. By doing this for each line, you can ensure that a separator is added at the end of each line in the text file.

<?php
$lines = array("Line 1", "Line 2", "Line 3");
$separator = " | "; // Define the separator

$file = fopen("output.txt", "w");

foreach ($lines as $line) {
    fwrite($file, $line . $separator . PHP_EOL); // Append separator to each line
}

fclose($file);
?>