Solved

Displaying some text containing carriage returns

Posted on 2002-04-17
8
160 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

743 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

15 Experts available now in Live!

Get 1:1 Help Now