Web Analytics Made Easy -
StatCounter Should I convert my <br> to /n or what ? - CodingForum

Announcement

Collapse
No announcement yet.

Should I convert my <br> to /n or what ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Should I convert my <br> to /n or what ?

    Hello

    I have a form that uses a <textarea> to allow formated paragraphs.

    In order to save this in the mySQL db I convert the carriage returns and new lines to brs with this:
    PHP Code:
    $value str_replace"\n"'<br>'$value );
    $value str_replace"<br />"'<br>'$value ); 
    $value trim(strip_tags($value,'<br>'));    
    $value str_replace(array("\r""\n"), ''$value); // Removes all newlines and carrige returns 
    This is fine for displaying the paragraphs but when the user then wants to edit the text in aform that uses a <textarea> they then get their text full of <br> s

    EG: This appears in the edit box.

    Code:
    This is a test documet<br><br>It should be nicel
    formated with the paragraphs that you entered
    <br><br>Please contact me if it isnt<br><br>thanks
    for looking.<br><br>Bye for now.
    Should I be changinging the <br>s back to "\r \n" or just \n ?

    The thing is I don't want it looking like this either:

    Code:
    This is a test documet\r  \n  \r  \nIt should be nicel
    formated with the paragraphs that you entered
    \r  \n \r  \nPlease contact me if it isnt\r  \n \r  \nthanks
    for looking.\r  \n \r  \nBye for now.
    It should look like this:

    Code:
    This is a test documet
    It should be nice formated with the paragraphs 
    that you entered
    
    Please contact me if it isnt.
    thanks for looking.
    
    Bye for now.
    But how do I get it back to this ?
    Thanks for helping
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Don't convert '\r\n' to <br> at the time of storage to db. Instead use nl2br() at the time displaying data.

    Comment


    • #3
      But I think that will mean that I will see this kind of thing when it is edited:

      This is a test documet\r \n \r \n It should be nicel
      formated with the paragraphs that you entered
      \r \n \r \n Please contact me if it isnt\r \n thanks
      for looking.\r \n \r \n Bye for now.
      Which looks as bad if not worst than the <br> s
      If you want to attract and keep more clients, then offer great customer support.

      Support-Focus.com. automates the process and gives you a trust seal to place on your website.
      I recommend that you at least take the 30 day free trial.

      Comment


      • #4
        If you are using a <textarea> element to edit the text (such as <textarea><?php echo $textvalue; ?></textarea>) then "\n" will become an actual line break in the html code and show up in the textarea as a line break.

        Comment

        Working...
        X