tags:

views:

28

answers:

2

I have a text area in html and a form to store the information in the database. When I click on submit, it supposed to take this text and save it in the database. For example:

"This is a text and this is a list:
1. number 1
2. number 2"

However, when I load the information from the database it looks like:

"This is a text and this is a list: 1. number 1 2. number 2"

How do I keep the layout of the textarea not changed (keep the spaces, lists, etc) without the need for the user to enter any tags.

+4  A: 

It's being stored just fine in the database. You're outputting what was entered as plain text as HTML, and HTML ignores line breaks. You need to convert your \n characters to <br /> tags. PHP has a nl2br() function for this.

ceejayoz
A: 

You could have them enter the data in a WSYWIG and do the work on your side to make sure it's always formatted properly - client-side users still won't have to see any tags, especially if you limit their editing options...

tinyMCE, nicEdit are two good editors

Silky