Results 1 to 7 of 7

Thread: Textarea & PHP - ignores new lines

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    56

    Question Textarea & PHP - ignores new lines

    Hi

    In my database there are two main sections, "view" and "edit".

    In the "Edit" section I have a textarea where I put some information on several paragraphs with a gap in between each paragraph.

    However, in the "View" section which just prints the contents of the textarea it ignores my gaps which I have put in using the enter key!

    This should be something simple to fix, but im new to PHP. How do I do it?!

    Many thanks

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    when you enter teh text and then hit enter and then you click on submit, where does it go and how do you save it to the db? also how do you pull it out of the db for that matter.

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You have two options:

    1) use str_replace() to replace the newlines with <br>
    Code:
    $str_to_replace = str_replace("\n", "<br>\n", $str_to_replace);
    2) Instead of just hitting enter twice, stick a <br><br> in there
    This is paragraph one.
    <br><br>
    This is paragraph two.
    <br><br>
    This is paragraph three.
    <br><br>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    PHP has a function specifically for this that produces XHTML-compliant code.

    nl2br()

    PHP Code:
    echo nl2br($row['text']); 
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by DJ P@CkMaN
    PHP has a function specifically for this that produces XHTML-compliant code.

    nl2br()

    PHP Code:
    echo nl2br($row['text']); 
    I've heard of a few people having problems with that function.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    I really hate when you answer posts and they never come back and let us know if it worked or not.

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    I really hate when you answer posts and they never come back and let us know if it worked or not.
    Me too, buddy.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width