Are there any best practices for maintaining formatting when using readfile to output files in PHP?

When using readfile to output files in PHP, the formatting of the file may not be maintained. To preserve formatting, you can use the ob_start() and ob_get_clean() functions to buffer the output before sending it to the browser.

ob_start();
readfile('file.txt');
$content = ob_get_clean();
echo $content;