Reputation: 9061
I have in database a string like : First line\r\nSecond Line
.
But when I put this text in textarea the \r\n
appears and there is no carraige return.
So how to add a carriage return in textarea ?
Thanks.
Upvotes: 1
Views: 5145
Reputation: 3780
I guess your database already contains a replacement character for the backslash and r
or n
. This would be not that good. Please make sure you are saving a real line break there. Then everything would be fine and you wouldn't need an extra replacement.
If you cannot change that, you can replace them back using this:
$str = preg_replace('/(\\\r)?\\\n/', "\n", $str);
Upvotes: 0
Reputation: 19237
'\n' is a symbol that means a new-line character. however adding '\n' in a text field of the DB won't translate the symbol to it's meaning.
\n should work, but you need to print it to your html correctly (so not as "\\n" or '\n', but "\n") See: http://jsfiddle.net/thqu3/
Upvotes: 1