Are there any best practices for reading and outputting multiple lines from a file in PHP?

When reading and outputting multiple lines from a file in PHP, it is best practice to use a loop to read each line of the file and output it accordingly. This ensures that all lines are processed and displayed correctly. Additionally, it is important to properly handle file opening, reading, and closing to avoid memory leaks or file access issues.

<?php
// Open the file for reading
$filename = "example.txt";
$file = fopen($filename, "r");

// Read and output each line from the file
while(!feof($file)) {
    $line = fgets($file);
    echo $line;
}

// Close the file
fclose($file);
?>