Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

    PHP? not recognizing line brakes with readfile{}

    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.
    http://i51.tinypic.com/347haww.png

    Out of desperation, I tried to CSS {white-space: nowrap} the DIV, but all I got was a single unbroken line:
    http://i51.tinypic.com/2qulp46.png

    Does anyone have any suggestions on how I can get PHP to recognize line brakes? or PHP design flaw?
    Last edited by Democrazy; 09-19-2011 at 07:29 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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

    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

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    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.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    Democrazy (09-19-2011)

  • #4
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Thanks tangoforce!

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

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    No, For everything is a solution.
    Maybe you don't know or you just can't think of a solution, there is always one.

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Democrazy View Post
    Thanks tangoforce!

    I'd rather sloppy code over no solution. Would you?!
    TBF, my code gives you a solution without <pre>, just sayin


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •