SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Textarea line breaks?

    got confused so I have to turn to this forum you again for help. Enclosed are a few screen shots/links tp my problem
    1st screen shot is of my form (The textarea in question to be precise) with some dribble in it (test with 2 line breaks, one after the last test and another before all the ks)

    the 2nd screenshot is an echo of what was inserted into my table (why is there no /n (line break) at either of those two spots)

    Lastly, this is the page where it is outputted
    http://mylaasp.com/provider_page.php?ID=9
    (How do I get new paragraphs at both of my like breaks?
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP problem really. New line is not a <br />, use nl2br before you output the paragraph.
    Saul

  3. #3
    SitePoint Addict dAEk's Avatar
    Join Date
    Oct 2003
    Location
    Stockholm, Sweden
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to replace the line feeds with
    1. <br />-tags for single line breaks
    2. regExps that encapsulate the text in paragraph tags (<p>) until a line feed (\n).


    The reason why you don't get the line feeds is:
    the new lines do get appended to the html, you can probably see that if you view the source code, but in html it's treated as white space, the same as a " " space.
    David Shamloo-Ekblad

    Go Habs! | For music addicts: Last.fm, SongMeanings

  4. #4
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    well, a new line is /n (right) so how come I dont see that when I output the data?
    "Oh, and Jenkins--apparently your mother died this morning."

  5. #5
    SitePoint Addict dAEk's Avatar
    Join Date
    Oct 2003
    Location
    Stockholm, Sweden
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. A new line in programming languages is \n. In html \n-characters (if that's the right term) are treated as white-spcace. Replace \n with <br /> and you should see some new line feeds. You could also put your output in <pre>-tags but that is not always an appropriate solution.
    David Shamloo-Ekblad

    Go Habs! | For music addicts: Last.fm, SongMeanings

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dAEk^
    No. A new line in programming languages is \n. In html \n-characters (if that's the right term) are treated as white-spcace. Replace \n with <br /> and you should see some new line feeds. You could also put your output in <pre>-tags but that is not always an appropriate solution.


    Just use nl2br and the problem is solved.
    Saul

  7. #7
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    My God, you are so smart (sweden seems to have loads of smart people) Unfortunatelly I'm one of the dumb people and didn't fully understand what u said. Let me start from the beginning, I have a textarea which people can enter stories if they want, what I want to happen is for them to create a new paragraph (</p><p>) whenever they press (Enter) inside that textarea?
    So that what is outputted is something like this
    HTML Code:
      this is a story.</p><p>2nd paragraph.</p><p>3rd paragraph
    Thanks a lot
    And I looked into nl2br but does it only work if there is a newline character (\n) which I cant seem to find? Also, id sort of like to use </p><p> instead of <br />
    "Oh, and Jenkins--apparently your mother died this morning."

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The newline is there, look at the html source.

    But if you want to replace it with </p><p>:
    PHP Code:
    $paragraphs=str_replace("\r","",$paragraphs);
    $paragraphs=str_replace("\n","</p><p>",$paragraphs);
    echo 
    "<p>".$paragraphs."</p>"
    Saul

  9. #9
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    ohhh

    I think your right but when I view the source I dont see\n, all i see is a new line (not the character, the \n is there, but the character is not displayed.
    "Oh, and Jenkins--apparently your mother died this morning."

  10. #10
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lukeurtnowski
    I think your right but when I view the source I dont see\n, all i see is a new line (not the character, the \n is there, but the character is not displayed.
    \n is a new line sybol, it is invisible. \n is used in programming to place a new line in a string:
    PHP Code:
    echo "line1\nline2"
    will be seen as:
    line1
    line2

    in html source.
    Saul

  11. #11
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Worked like a charm, thanks
    whats \r mean anyway?
    "Oh, and Jenkins--apparently your mother died this morning."

  12. #12
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    \r is carriage return symbol, it's used in windows so the line break is: \r\n. Knowing the user input may come from windows, \r may be present, so we need to remove it.
    Saul

  13. #13
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks
    "Oh, and Jenkins--apparently your mother died this morning."


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
  •