I had the same problem. The correct answer is much simpler. Don't use nl2br with pre.
nl2br adds <br />
to text for html, but the pre tag already preserves the text format.
That's what it means. <pre>
= preformatted.
Yes, something like this will work, until it doesn't.
<pre>
preg_replace ("/[\n\r]+/", "",nl2br(file_get_contents("/crashbody.txt")))
</pre>
But that's silly. You're adding line breaks and removing them. To preserve your whitespace and your line breaks, let <pre>
do it's job.
<pre>
file_get_contents("/crashbody.txt")
</pre>
Or better still:
<div style = "white-space: pre; text-align:left;">
file_get_contents("/crashbody.txt")
</div>
nl2br
will insert<br />
for each\r
and for each\n
if there's any character at all between them. Show your input string. – Edaphic