SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Line returns - Text formatting

    Not sure if this is a php problem or not.

    I have a html form that has a text box. The text is entered and the user puts in breaks eg

    "The BBC telethon Children in Need raised more than 17.2m during the fund-raising campaign on BBC One.

    The total is slightly higher than last year and is expected to grow to more than 30m when all donations are in.

    Presenter Terry Wogan said: "Thank you for all your donations and everything you have done for Children in Need."
    The text is submitted and it is inserted into a database. However upon retrival it comes out as 1 continuous piece eg

    The BBC telethon Children in Need raised more than 17.2m during the fund-raising campaign on BBC One. The total is slightly higher than last year and is expected to grow to more than 30m when all donations are in. Presenter Terry Wogan said: "Thank you for all your donations and everything you have done for Children in Need."
    How can I make it so that it will do the line breaks and maybe even some text formatting, like bold etc?

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See nl2br

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, does that mean the user would have to type /n at the end of each paragraph?

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, the newlines from the textarea (when the user presses enter) go into the databases as is, you don't need to change anything there, when you want to display the info from the database just pass it through nl2br() first, for example:

    echo nl2br($row['thetext']);

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent, that worked a treat! Such an easy fix too.


Bookmarks

Posting Permissions

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