Solved

Displaying some text containing carriage returns

Posted on 2002-04-17
8
165 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 190 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
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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 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