Solved

Displaying some text containing carriage returns

Posted on 2002-04-17
8
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

734 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