开发者

How to preserve the layout of textarea in the database?

开发者 https://www.devze.com 2023-01-04 10:22 出处:网络
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:

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 d开发者_开发问答atabase 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消