473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.

Apr 28 '06 #1
5 16814
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: dan glenn | last post by:
Hi. I'm finding that if I have text entered into a <textarea ...> </textarea> in a form, and that text has leading blank lines (with no spaces or anything else), that when I retrieve the entered...
6
by: Jonathan | last post by:
I want to save textarea contents to a mysql database with the paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally...
4
by: Travis Pupkin | last post by:
Hi, I'm putting together a site to allow someone to add content to a DB through a text area form, and then display it on the web. Pretty basic. The problem I'm having is that they need to add...
3
by: EmmettPower | last post by:
Hi, I am building a small CMS for my son's school. Ideally I want to build the system for them and hand it over so that all updates can be done through web-based forms. So far so good....
11
by: Johnny Two Dogs | last post by:
I'm strictly concerned with IE, so cross-browser compatibilty isn't necessary. If you view the code below, I almost get exactly what I'm looking for: - A table of four cells that...
2
by: Chris Schinzel | last post by:
Hi, I'm reading text from a html textarea field (standard wrap functionality, no value specified). If I display it via nl2br() (after html form submission), everything's ok. But if I send it via...
14
by: ghostwalker | last post by:
Hi I have an HTML form with a textarea on it. When submitted (using 'get' not 'post') this forms action php file simply does this to retrieve the values: $message = $_GET; Now it all works...
3
by: Ciaran | last post by:
Hi can someone give me the code to convert a line break in a multiline textfield to a <br/tag ? It's something to do with CR LF but I can't find the exact code anywhere. Cheers, Ciarán
5
jmitchell
by: jmitchell | last post by:
I've been trying to work out this very simple thing for hours now and I wonder if you can help. My form submits the value of textarea, then takes the value and emails it in a plaintext email. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.