September 16th, 2004, 01:42 PM
Preserving new line characters
I have a form with a text area where users can enter text and submit.
However, when I display the data that the user submitted, it doesn't preserve the formatting. What I mean is, the new line characters seem to just get ignored even though it's in the DB.
This post is a good example of what I want to happen. Preserving all 4 paragraphs when displayed to the forum.
Any ideas? Thanks in advance!
September 16th, 2004, 04:08 PM
Am I right to presume you are displaying this in an html page? If so then the problem is not that the formatting is being lost, but it is not being displayed.
HTML does not display whitespace, converting runs of whitespace (including spaces, tabs, linefeeds, carriage returns etc) into a single space. You will need to replace the line endings with <br> tags, and if you want to preserve indentation you will need to replace spaces with .
Dave - The Developers' Coach
September 16th, 2004, 04:26 PM
Originally Posted by DevCoach
Did what you said and it worked perfect. Did something like this:
var = var.replace("\n","<br>")
Just curious, is there another way to do this using a library or some other function? Something like an encode or decode sort of thing?