How can the use of <pre> tags maintain text formatting in PHP when reading from a text file?

When reading text from a file in PHP, the formatting such as line breaks and spaces may not be preserved when displaying the content on a webpage. To maintain the text formatting, you can use the <pre> HTML tag which preserves whitespace and line breaks. Simply wrap the content from the file in <pre> tags before displaying it on the webpage.

&lt;?php
$file = &#039;sample.txt&#039;;
$content = file_get_contents($file);
echo &#039;&lt;pre&gt;&#039; . $content . &#039;&lt;/pre&gt;&#039;;
?&gt;