How can the use of line breaks and character encoding impact the output of file data in PHP?
Line breaks and character encoding can impact the output of file data in PHP by causing formatting issues or displaying special characters incorrectly. To ensure proper output, it is important to handle line breaks and character encoding appropriately when reading or writing files.
// Set proper character encoding
header('Content-Type: text/html; charset=utf-8');
// Read file data and handle line breaks
$fileData = file_get_contents('example.txt');
$fileData = nl2br($fileData);
// Output the file data
echo $fileData;