4

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?

3 Answers 3

5

use <pre></pre>

Sign up to request clarification or add additional context in comments.

Comments

0

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

Also, replace \n with <br />

Hope that helps!

1 Comment

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.
-1

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)

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.