#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Cool LineBreaks from MySQL to PHP?


    How can you get the line breaks to work when you retrieve data from MySQL to PHP?4 Blue
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    Depends. Where are these line breaks going? What does your code look like?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0
    Originally Posted by icechua
    How can you get the line breaks to work when you retrieve data from MySQL to PHP?
    Is the issue that the data in the database contains new-line or carriage-return characters and you wish the output to represent that to the user?

    Then you need to understand that what you display to the user is in HTML. The browser, as you have observed, ignores line breaks. So wherever there is a line break in the input data you need to insert a <br> or <p>. For example:

    Code:
    print str_replace("\n","<p>",$value);
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,405
    Rep Power
    594
    What jcobban says is only partly true. The browser will honor line breaks if you enclose the text in <pre></pre> tags. Of course then all of the enclosed text has to be formatted for it to look the way you want.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    Sydney Australia
    Posts
    183
    Rep Power
    83
    Originally Posted by gw1500se
    What jcobban says is only partly true. The browser will honor line breaks if you enclose the text in <pre></pre> tags. Of course then all of the enclosed text has to be formatted for it to look the way you want.
    Or you could just pass your text through nl2br() to convert newline to <br>

IMN logo majestic logo threadwatch logo seochat tools logo