I have a form that inserts blob text into a database.
When i insert it into the database using a textarea, it works fine.
For example, if i put this text into the textarea field:
test
ss
f
f
f
dsdfdsf
sdfsdfsdf
it saves it into the database as:
test
ss
f
f
f
dsdfdsf
sdfsdfsdf
So thats fine, now when i fetch the data from the database and echo it onto a div, i use nl2br(), and the divs content becomes:
test
ss
f
f
f
dsdfdsf
sdfsdfsdf
So thats still fine
HOWEVER
If i echo the output from the database into a textarea, it becomes:
test
ss
f
f
f
dsdfdsf
sdfsdfsdf
That is not using nl2br, if i do use nl2br, the textarea becomes:
test<br /><br /><br />ss<br />f<br /><br /><br /><br />f<br />f<br /><br /><br /><br /><br />dsdfdsf<br /><br /><br />sdfsdfsdf
And i want new lines, not (br /), you can see it knows how many lines there should be, but when i dont use nl2br, it will only do up to 1 new line in a row.
Ive tried googling around, and all i can find is people asking how to echo the database content to a div, but for me, it works fine to a div (with nl2br), its just to a textarea…
Ive also tried giving the textarea the css attribute: ‘white-space: pre;’, but that doesnt work either.
You can’t use
nl2brif you are outputing the data into a textarea. Just output the data (with htmlspecialchars).The textarea will see the \n (newlines) as a div will see
<br />.http://jsbin.com/uzinut/1