Solved

Displaying some text containing carriage returns

Posted on 2002-04-17
8
162 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

776 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