By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

Line Breaks in a Textarea

P: n/a
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.

Apr 28 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
jo******@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
Apr 28 '06 #2

P: n/a
Rik
jo******@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
Apr 28 '06 #3

P: n/a
Message-ID: <e2**********@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/
Apr 28 '06 #4

P: n/a
Rik
Geoff Berrow wrote:
Message-ID: <e2**********@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


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
Apr 28 '06 #5

P: n/a
jo******@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.

Apr 29 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.