Line Breaks in a Textarea

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joelbyrd@gmail.com

    #1

    Line Breaks in a Textarea

    Didn't know exactly where to post this, but: How do I get line breaks
    in a textarea? I'm pulling text from a database, and this text
    definately has line breaks in it, because I
    replaced all the line breaks with <br /> tags ( using the php function
    nl2br() ), and <br /> tags showed up in the textarea.

  • Chris Hope

    #2
    Re: Line Breaks in a Textarea

    joelbyrd@gmail. com wrote:
    [color=blue]
    > Didn't know exactly where to post this, but: How do I get line breaks
    > in a textarea? I'm pulling text from a database, and this text
    > definately has line breaks in it, because I
    > replaced all the line breaks with <br /> tags ( using the php function
    > nl2br() ), and <br /> tags showed up in the textarea.[/color]

    If you don't use nl2br(), and the text has line breaks in it, then those
    line breaks will actually show up as line breaks in the textarea. You
    don't need the <br /> tags.

    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

    Comment

    • Rik

      #3
      Re: Line Breaks in a Textarea

      joelbyrd@gmail. com wrote:[color=blue]
      > Didn't know exactly where to post this, but: How do I get line breaks
      > in a textarea? I'm pulling text from a database, and this text
      > definately has line breaks in it, because I
      > replaced all the line breaks with <br /> tags ( using the php function
      > nl2br() ), and <br /> tags showed up in the textarea.[/color]

      GOOGLE: html textarea line-break

      Further:[color=blue]
      > this text definately has line breaks in it, because I replaced all the[/color]
      line breaks with <br /> tags"

      Do you mean: "this text has lost his line-breaks because I replaced them"?

      Have you replaced all the line-breaks BEFORE adding it to the database (to
      store html-code for example)? If so:
      $string = str_replace("<b r />", "<br />\n", $string);

      Else: don't use nl2br() while displaying it in a textarea.

      Compare the following code in your browser:
      <textarea>this< br />is<br />some<br />text</textarea>
      <textarea>thi s
      is
      some
      text
      </textarea>


      Note:
      "\n" works, '\n' doesn't, at least here on w2k with PHP 5.0.5, I have no
      idea wether this is always the case.

      Grtz,
      --
      Rik Wasmus


      Comment

      • Geoff Berrow

        #4
        Re: Line Breaks in a Textarea

        Message-ID: <e2u3ak$8om$1@n etlx020.civ.utw ente.nl> from Rik contained
        the following:
        [color=blue]
        >Else: don't use nl2br() while displaying it in a textarea.[/color]

        AFAIK nl2br() adds a <br /> butt doesn't remove the \n

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Rik

          #5
          Re: Line Breaks in a Textarea

          Geoff Berrow wrote:[color=blue]
          > Message-ID: <e2u3ak$8om$1@n etlx020.civ.utw ente.nl> from Rik contained
          > the following:
          >[color=green]
          >> Else: don't use nl2br() while displaying it in a textarea.[/color]
          >
          > AFAIK nl2br() adds a <br /> butt doesn't remove the \n[/color]

          Yup, but in shows "<br />" in the textarea, so you get line-breaks, and on
          every end a useless <br />.
          Which would you prefer:
          <?php
          $string="aksfdj al\nsgfhsflijsl fj\nsdihflsjfld sf";
          ?>
          <textarea><?p hp echo nl2br($string); ?></textarea>
          <textarea><?p hp echo $string; ?></textarea>

          Grtz,
          --
          Rik Wasmus


          Comment

          • khoa.tran

            #6
            Re: Line Breaks in a Textarea

            joelbyrd@gmail. com wrote:[color=blue]
            > Didn't know exactly where to post this, but: How do I get line breaks
            > in a textarea? I'm pulling text from a database, and this text
            > definately has line breaks in it, because I
            > replaced all the line breaks with <br /> tags ( using the php function
            > nl2br() ), and <br /> tags showed up in the textarea.[/color]

            The line-break in textarea is "\n", not <br /> tag. So, if you get data
            from one textarea and display in another textarea, you don't need to
            convert anything.

            Comment

            Working...