php - What's happening to new lines in my form textarea? -


i have simple form consisting of textarea. within textarea markdown syntax want save database. it's important preserve carriage returns/new lines.

when form submitted though, newlines don't seem sent server unless use nl2br() php function.

on server, grab contents of message textarea this:

$content = $_post['message']; 

if echo with:

echo $content; 

the text on 1 long line.

if echo with:

echo nl2br($content); 

it shows content expected. why this? i'm assuming if save value of $content database new line characters preserved?

the browser submits newlines lf characters (=\n).

if output these, browser won't display them because ignores newlines in normal html rendering mode. if convert them <br> tags, browser recognize them.

try setting content type text/plain , see browser renders line feeds:

header('content-type: text/plain'); echo $content; 

save data unformatted database, i.e. not convert them <br> tags. conversion when you're outputting data.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -