Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Displaying some text containing carriage returns

Posted on 2002-04-17
8
Medium Priority
?
182 Views
Last Modified: 2012-05-04
I'm trying to display some text that I've retrieved from a database on a HTML form. The text contains several carriage returns but when I display it on the web page it just shows as a continuous stream of text - in other words, all the formatting is lost. I'm currently just writing the text in a table cell (i.e. a plain <td> .. </td>).

Can anyone suggest a solution ?

Thanks
0
Comment
Question by:ggale
8 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6947601
You will need to do it with server side scripting to replace the carriage returns with <br />.  Browsers will treat carriage returns as white space, and will not respond to them.

Cd&
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6947610
If it's ASP, you can do it like this:

Replace(rs("thefield"), vbCrLf, "<br>")

If in Perl...I have no idea...

Max.
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 760 total points
ID: 6947611
The only other thing that might work is to put the text between <pre> and </pre>  then the browser will keep the formatting in the generated code.

Cd&
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:jpoesen
ID: 6951065
Every server-side scripting language provides the appropriate functions to convert CR/LF to <br>.
In ASP, it's indeed

Replace(rs("thefield"), vbCrLf, "<br>")

In PHP it's

nl2br($rs->thefield)


jpoesen.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6951122
jpoesen,

Welcome to Experts-Exchange.  Please read the guidelines for answers and comments.  By using the answer option instead of a comment you have locked the question out of the active list, and reduced the chances that the user will receive additional useful comments.  The answer you supplied does not supply anything that has not already been said and is far from being a definitive answer.  If you observe the top-experts you will notice that they submit comments only 99% of the time to keep the collaborative process open and continuing.

I will be asking a moderator to rejuct your answer to put the question back onto the active list.  Their is no need to be offended by this, as it is a common mistake for new members to misunderstand the difference between answers and comments.

Cd&
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6951195
jpoesen,

Welcome to Experts Exchange!

I have rejected your Proposed Answer; you should only leave your remarks in the form of an Answer when you are absolutely, 100 per cent certain that your suggestion is the ONLY perfect solution to the problem posed by the Asker, and ONLY if your comments don't duplicate, paraphrase or enhance someone else's remarks.

Experts Exchange is a collaborative site, and when you "Answer", as opposed to "Comment", you lock the question and remove it from the easily seen open questions. That inhibits the collaborative process.

The Asker sees a button which says Accept This Comment As Answer (even on rejected Answers), so if the Asker likes your choice, you'll get the points and the grade.

Netminder
CS Moderator
0
 

Author Comment

by:ggale
ID: 6952797
Spot on ! - simple and quick.

Thanks
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6953235
Sometimes old-fashioned simple tagging is all it takes.  Glad we could help.  Thanks for the A. :^)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

971 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