View Full Version : PHP? not recognizing line brakes with readfile{}

09-19-2011, 08:21 AM
I am using the PHP readfile() argument to output my server access.log file inside a DIV.
The problem I am having is that the lines brakes are not being recognized.

Out of desperation, I tried to CSS {white-space: nowrap} the DIV, but all I got was a single unbroken line:

Does anyone have any suggestions on how I can get PHP to recognize line brakes? or PHP design flaw?

09-19-2011, 09:08 AM
The problem with carridge return's in PHP/HTML, (\n, or sometimes \r\n), is that they only return a new line for plain text. HTML is a markup language, meaning layout is defined by the tags, not the plain text. So, although \n's will return new lines in the plain text (HTML source), they'll not produce a new line in actual browser output (in normal operation).

To solve that, you should look at the nl2br() function - http://php.net/manual/en/function.nl2br.php - which will insert a <br /> tag before every \n :thumbsup:

An alternative to that, would be to use <p> tags in the areas you want. Completely up to how you want to output your code :)

09-19-2011, 12:34 PM
You can also use the <pre></pre> tags which tells the browser to preserve the formatting of the text. Note though that it is considered sloppy by some coders.

09-19-2011, 01:12 PM
Thanks tangoforce!

I'd rather sloppy code over no solution. Would you?!

09-19-2011, 01:15 PM
No, For everything is a solution.
Maybe you don't know or you just can't think of a solution, there is always one.

09-19-2011, 01:18 PM
Thanks tangoforce!

I'd rather sloppy code over no solution. Would you?!

TBF, my code gives you a solution without <pre>, just sayin :p