Solved

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

Posted on 2009-05-02
7
328 Views
Last Modified: 2014-11-12
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
0
Comment
Question by:fun_g
  • 4
  • 3
7 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24288487
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.
0
 

Author Comment

by:fun_g
ID: 24288521
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
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24289426
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().
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:fun_g
ID: 24289967
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

0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24290669
Have you tried nl2br()? Try the code below.

>> How can I call it to a <textarea>

"call it"... do you mean display it in a textarea? Just wrap it in a textarea tags:

$return .= "<div id=\"tDSText5_$dietsheet->cf_id\"><textarea>{$tmp}</textarea></div>";

If you use a textarea, you should NOT use nl2br().

PS: I added a semicolon to your &nbsp; In many cases the browser will understand it without the ; but it is correct to end it with a ; character.
$tmp = ($dietsheet->text_5) ? nl2br($dietsheet->text_5) : "&nbsp;";

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24290676
Heh! I forgot, EE removes the &nbsp; from the code snippet. The " " at the end of the code snippet contained &nbsp; (nonbreakable space)
0
 

Author Comment

by:fun_g
ID: 24292210
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
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This Micro Tutorial  demonstrates whether your site uses one subdomain or multiple subdomains, how to create full URLs from Google Analytics content reports. This procedure is called concatenation and can also be done with the CONCATENTATE function.…
This Micro Tutorial will demonstrate how to analyze your website's back links using a network graph powered by a fusion table.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now