How can the use of the file() function in PHP lead to unexpected line breaks in the output?
When using the file() function in PHP to read a file, each line of the file is returned as an element in an array. If the file contains line breaks that are not consistent (e.g., a mix of "\n" and "\r\n"), it can lead to unexpected line breaks in the output when the array elements are echoed. To solve this issue, you can use the file_get_contents() function to read the file as a string and then use the explode() function to split the string into an array based on a consistent line break character.
$file_contents = file_get_contents('example.txt');
$lines = explode("\n", $file_contents);
foreach($lines as $line){
echo $line . "<br>";
}