Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1981
  • Last Modified:

PHP: How to deal with line break in text area?

I have a text area, but when user type stuff and then hit line break, and write stuff, when I get the data from $_POST and then store in db, and then retrieve from db and print on web page, the content just become one paragrah without any line break.

Any idea how to solve that?
0
jtcy
Asked:
jtcy
2 Solutions
 
b0lsc0ttCommented:
First check to see if the line breaks are in the data in your database.  If so you just need to use nl2br() to convert the data from the database for the webpage.  The new line characters will be replaced with the <br> tag.  If it is hard to look at your data in the database then view the html source of the page.  If you see the line breaks in the source then the nl2br() function will do it.

If you need help storing the new lines in the database then let me know and I can help with that.  Let me know if you have a question or need more info.

bol
0
 
RoonaanCommented:
In addition to b0lsc0tt, note that you need to do nl2br after your htmlspecialchars:

echo nl2br(htmlspecialchars($contents))

-r-
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now