Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line breaks in HTML from <textarea> input

Status
Not open for further replies.

jimoblak

Instructor
Oct 23, 2001
3,620
US
This may be a basic HTML question but I am wondering if PHP is used to process this...

I would like to do something like what is shown on the page you are looking at. At the bottom of the page is a text box ('Step 3 Message'). When you type in an extra 'return' to make a paragraph break, it is displayed with breaks in the text box (or the HTML <TEXTAREA> in the <FORM>). These paragraph breaks are also displayed on the next page when you hit 'Preview Post'.

I have a similar page on my site but after the form is submitted, the text gets smashed into a single paragraph with no breaks. Is there something simple that I can do to display these breaks?

Is PHP used to insert a '<BR>' whenever a 'return' character is read? How is this done?


Thanks!
 
PHP can do this using a thing called regular expressions. Regular expressions are used in regex functions to do powerful string manipulation.

What form interpreter are you currently using? Perl is another language that has very powerful regular expression capabilities.

PHP Manual page for regex:
 
well it's even easier!!!!

try this:

<?
$text = &quot;this is
a text
wich has
some line breaks&quot;;

## this will display the line breaks as <br>
echo nl2br($text);
?>

reply to fedebaseggio@hotmail.com
my email wasn't requested...
 
I think this could be what you are looking for ,try this:<textarea wrap=hard>.
 
fede_ar is right; nl2br() converts any &quot;new line&quot; character to a &quot;<BR />&quot; HTML tag (which is a <BR> tag, but is also compliant with XML or DHTML or something)

So simply put the <TEXTAREA> input through the nl2br() function, and it will output all new lines as HTML line breaks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top