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 3 of 3

Thread: line breaks

  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    line breaks

    Hi...I have little problem on at moment....my problem is i'm trying to build a php data driven website.....the problem is when i display the data from the data.....its broken up my html table structure...is there anyway i can Maintain the line breaks

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you mean linebreaks, for instance, like the ones created by <textarea> form fields ("\r", "\r\n" or "\n") then you can turn these into <br /> tags that will show up when you echo your HTML by using the nl2br() function, eg if you have some data in a variable called $data:
    PHP Code:
    echo nl2br($data); 

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I want to add this as well, nl2br function doesn't convert the new lines, it mearly adds a <br /> in front of it for html processing. This is most likely the function you are looking for, but beware of that aspect, I've seen a few sites that required the newlines to be destroyed (which requires either a replacement pattern (useless for this function), or a simple str_replace).


  •  

    Posting Permissions

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