3

Possible Duplicate:
Newline Conversion in Submitted Text in PHP

I'm using PHP to store text submitted from a textarea into a database to later be echoed out. If a user presses enter in the textbox to start a new line, I want it to start a line break.

How can I go about doing that?

Let's say this is the textbox:

This is line one.
This is line two.

When a user submits this to the database it is just stored as one line and echoed out is the same result. "This is line one. This is line two."

So how do I make the stored text reflect the format of the original input?

Community
  • 1
  • 1
Query
  • 720
  • 2
  • 7
  • 23

1 Answers1

8

You would run something like nl2br() on your output when reading FROM the database. The new lines will be stored as \n.

http://php.net/manual/en/function.nl2br.php

It should also be noted that you should not run nl2br() before inserting into the database. Just not a good practice.

Kai Qing
  • 18,793
  • 5
  • 39
  • 57