Link to home
Start Free TrialLog in
Avatar of fun_g
fun_gFlag for United States of America

asked on

How can I place a carriage return in text field from database?

I have setup a multi-line text field for entry to a database. Many users try separating items and tesk by hitting enter supplying them with a new line within the text field although when the data is queried and displayed in the page it does not show the carriage return that has been used for oganization.

I have seen this on Google calendar and I am trying to get that look. How is this done?

Thank you all,
gorg
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Use the nl2br() function:

http://php.net/manual/en/function.nl2br.php

This function converts linefeeds to <br> tags, so that they break lines in html.
Avatar of fun_g

ASKER

cxr,
Thank you very much for your quick response.
This function looks like it is more geared for line by line query from the database. I am submitting a text field and calling the text field to display the data on the page. Within the text field I need to preserve the carriage returns for display within the text box on the page.

Thank you,
gorg
Can you show your code?

>> for display within the text box

What kind of text box? A <textarea>? Or a paragraph <p> or <div>?

For a textarea, no conversion should be necessary. For a paragraph or div, use nl2br().
Avatar of fun_g

ASKER

The entry in the form is a <textarea> but the code that I am calling it back with is listed below. How can I call it to a <textarea>. Lack of knowledge here. :(



$return .= "<td>";
														$tmp = ($dietsheet->text_5) ? $dietsheet->text_5 : "&nbsp";
$return .= "<div id=\"tDSText5_$dietsheet->cf_id\">{$tmp}</div>";
$return .= "<input id=\"tbDSText5_$dietsheet->cf_id\" style=\"display: none; float: left; width: 70%\" type=\"text\" value=\"{$dietsheet->text_5}\">";
$return .= "</td>";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Heh! I forgot, EE removes the &nbsp; from the code snippet. The " " at the end of the code snippet contained &nbsp; (nonbreakable space)
Avatar of fun_g

ASKER

cxr,
The addition 'n12br' worked perfect. Thank you very much. This has loaded the page with the correct format. Thank you for your time.
gorg