Home > Archive > PHP Programming > April 2006 > Line Breaks in a Textarea
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Line Breaks in a Textarea
|
|
| joelbyrd@gmail.com 2006-04-28, 6:58 pm |
| 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 2006-04-28, 6:58 pm |
| joelbyrd@gmail.com 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.
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
| |
|
| joelbyrd@gmail.com 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
| |
| Geoff Berrow 2006-04-28, 6:58 pm |
| Message-ID: <e2u3ak$8om$1@netlx020.civ.utwente.nl> from Rik contained
the following:
>Else: don't use nl2br() while displaying it in a textarea.
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/
| |
|
| Geoff Berrow wrote:
> Message-ID: <e2u3ak$8om$1@netlx020.civ.utwente.nl> from Rik contained
> the following:
>
>
> AFAIK nl2br() adds a <br /> butt doesn't remove the \n
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="aksfdjal\nsgfhsflijslfj\nsdihflsjfldsf";
?>
<textarea><?php echo nl2br($string); ?></textarea>
<textarea><?php echo $string; ?></textarea>
Grtz,
--
Rik Wasmus
| |
| khoa.tran 2006-04-29, 6:58 pm |
| joelbyrd@gmail.com 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.
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.
|
|
|
|
|