How do i do this using php

Discussion in 'Programming' started by mumfry, Jan 7, 2013.

  1. #1
    I have a mysql database with a paragraph save

    but every time i display/echo it out it shows like so
    The Funniest Thought - : ) "Always Smile in the Morning...... It makes people wonder that what u did last night..!!.."

    All in one line

    Is there any way to get it to keep the original format just like the way its saved in the database with all the breaks instead of having it display in just one line

    any help would be greatly appreciated
    Thanks
     
    mumfry, Jan 7, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    If you want to display it that way on a web page, the breaks have to be <br />, not line terminations. If you're using PHP, you can use

    echo nl2br($yourtexthere);

    That will convert the text from having line breaks to having HTML breaks.
     
    Rukbat, Jan 7, 2013 IP
  3. premiumwordpressthemes

    premiumwordpressthemes Active Member

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    96
    #3
    Actually you have 2 options:

    1. use nl2br for the output as Rukbat mentioned.
    2. try using an HTML editor such as TyniMCE or CKEditor to edit that text. The Editor will automatically add breaking line tags for you!

    Good luck!
     
    premiumwordpressthemes, Jan 8, 2013 IP
  4. dsmlacctv

    dsmlacctv Greenhorn

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #4
    thanks for posting this thread i was searching for this problem.double thanks to rukbat :)
     
    dsmlacctv, Jan 24, 2013 IP