In PHP, what are the potential pitfalls of using the file() function when reading files with line breaks?

When using the file() function in PHP to read files with line breaks, the function will include the line break character at the end of each line in the array. This can cause issues when processing the lines as it may not be expected. To solve this, you can use the array_map() function with rtrim() to remove the line break characters from each line before processing them.

$lines = file('example.txt');
$lines = array_map('rtrim', $lines);

// Now $lines array contains lines without line break characters
foreach($lines as $line) {
    // Process each line without worrying about line breaks
    echo $line . PHP_EOL;
}