How can the file() function in PHP be utilized to read lines from a text file?

To read lines from a text file in PHP, you can use the file() function, which reads the entire file into an array where each element represents a line from the file. You can then iterate over this array to process each line individually.

$lines = file('example.txt');

foreach ($lines as $line) {
    echo $line . "<br>";
}