SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi lines problem..

    Hello guys..

    well, I am making a guestbook script.. and having a problem!

    when I post the comments, I write the comments in this form:

    Hey, I am John,

    I like really like this site,
    keep it up,

    Regards,
    John
    John Company
    but when I browse the comments its in this form:
    I am John,I like really like this site,keep it up,Regards,John John Company
    any ideas ?

  2. #2
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw: I want to have the comments in the same form as the user submitted without any WYSIWYG Edititor....

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php.net/nl2br

  4. #4
    SitePoint Zealot swiftone's Avatar
    Join Date
    Mar 2005
    Location
    Sunny Florida
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    other options

    You need to add in \n for newlines or \r for returns. If you are doing the output as html you may want to include html markup such as <p></p> or <br>.
    Happy Coding,
    Swiftone

    Unique Web Sites

  5. #5
    SitePoint Guru defiance's Avatar
    Join Date
    Oct 2004
    Location
    United states
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by someonewhois
    php.net/nl2br
    +1

  6. #6
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Nathan that worked..

    I just used the nl2br function and it worked!

    PHP Code:
    $message $_POST["message"];
    $message nl2br($message); 
    and it worked

    Thanks again

  7. #7
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use nl2br on output, not input. That way, if you have to read it back (say, in a textarea), you don't need to strip the <br/> tags. Plus, if you ever want to format it differently (ie. double space), you can easily change it on output - you can't easily change it if the HTML is in the database. Plus DB's are for content, not code.


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
  •