views:

82

answers:

3

I only want to maintain the paragraph structure of the users input into a textbox. When I retrieve the text from db, all structure is lost. What's easiest way to save text as recorded?

A: 

replace spaces " " with   You can't repeat multiple spaces " " in HTML, as they will be collapsed into one space.

Also, replace \n with <br />

Hope that helps!

ItzWarty
Whilst this will work, it's a lot of hassle, compared to wrapping the text in a <pre></pre> element, as suggested by @Skay. You would need to consider tabs too, which is a whole new ball game.
belugabob
A: 

If you want to store HTML text (rich text with BOLD , Italic and etc) you have to use an editor like CKEditor (http://www.ckeditor.com)

Nasser Hadjloo
The question was not about entering HTML, it was about preserving and displaying the whitespace that is inherent in the text entered via a textbox (I'm presuming a <textarea> element)
belugabob
+1  A: 

use <pre></pre>

Skay