So I have an input text area. and on submit it puts the text into the DB. The formatting stays. But when I echo it, the formatting goes away (for example text like:
this is line one.
this is line 2
turns into:
this is line one this is line 2)
So I decided to use the <pre> tag and echo the database row. It worked, the formatting came back. HOWEVER when a line is more than say 50 characters long, it throws off the table borders (obviously because <pre> does not wrap lines). What is a better way to echo a row but keep the formatting?
Remain formatting in DB and when using ECHO
Moderator: General Moderators
You might need to use the function nl2br() when you want to echo it on a page. Or even store it that way in the DB, if you want.
nl2br() will turn the new lines (\n) into <br /> (line break tag).
Usage:
nl2br() will turn the new lines (\n) into <br /> (line break tag).
Usage:
Code: Select all
echo nl2br("this is line one\n\nthis is line two");Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
It does have those characters. They just aren't visible.waradmin wrote:Well when I use text as the data type in the row it keeps the formatting in the DB. I just cant echo it. Now with that function it takes \n and turns it into <br>, but how do you then take an input, and have it add in \n for each new line added when in the DB it doesnt have those characters?
When you type in a textarea
Code: Select all
this is line one
and this is line twoCode: Select all
this is line one\n
\n
and this is line twoSet Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.