Re: Line Breaks in a Textarea



joelbyrd@xxxxxxxxx wrote:
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.

GOOGLE: html textarea line-break

Further:
this text definately has line breaks in it, because I replaced all the
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("<br />", "<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>this
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


.



Relevant Pages

  • Re: Multiline database entries
    ... what I'm trying to do is get a private message sent between two ... >>TEXTAREA and then PHP handles the storing of everything to a MySQL ... >>Using a blob in the database ... > First for that u dont need a blob field but a Text is enough, ...
    (alt.php)
  • Re: Multiline Textbox Problems
    ... I am using the textarea to enter the data from the form into the ... In this site you will find some php code. ... The data was saved in the database field exactly the same. ... displaying come from the database. ...
    (comp.lang.php)
  • Re: Creating session variables in GLOBAL.ASA ???
    ... WYSIWYG editor ... all i am working on a textarea where X number of char reaches in a line then ... >> Eventually I'll need to access a database and I'm assuming that if I ...
    (microsoft.public.inetserver.asp.general)
  • Re: Creating session variables in GLOBAL.ASA ???
    ... WYSIWYG editor ... all i am working on a textarea where X number of char reaches in a line then ... >> Eventually I'll need to access a database and I'm assuming that if I ...
    (microsoft.public.inetserver.iis.activeserverpages)
  • Re: Creating session variables in GLOBAL.ASA ???
    ... WYSIWYG editor ... all i am working on a textarea where X number of char reaches in a line then ... >> Eventually I'll need to access a database and I'm assuming that if I ...
    (microsoft.public.inetserver.iis.activeserverpages)