0

I'm sorry if the title sounds confusing but I don't know how to express the problem in one line. Anyway here are the details,

I have a textarea in which the user input data and then I store the data in my MySQL 5.5 database. The user inputs the data in well formated form i.e. leaving lines using 'enter key'.

Eg:

text text text text

text text text

text text text text text text

Now when I retrieve the data from the database it is not displayed in the form as it was entered by the user but as follows,

Eg:

text text text text text text text text text text text text text

Is there a way through which I can make the format of the text same as it was entered by the user?

Saumil
  • 2,521
  • 5
  • 32
  • 54
  • possible duplicate of [Why entered key word is not store in database?](http://stackoverflow.com/questions/2816262/why-entered-key-word-is-not-store-in-database) – Mudassir Hasan Apr 30 '14 at 05:49
  • please share your html code or jsfiddle. – Bhushan Kawadkar Apr 30 '14 at 05:50
  • @mhasan the link you gave is for PHP, can you provide me anything for JSP? – Saumil Apr 30 '14 at 05:51
  • 1
    possible duplicate of [Storing TextArea data with line breaks in database and displaying in same format with line breaks](http://stackoverflow.com/questions/10062358/storing-textarea-data-with-line-breaks-in-database-and-displaying-in-same-format) – Quentin Apr 30 '14 at 05:55

1 Answers1

2

when you insert the data from textarea new line will be marked as \n so when you retrieve it and display it in textarea it will display the same as you entered.

But if you want to display it on the html. you will see the plan text without new line because html cannot understand the \n so replace \n with html new line tag <br/>

$string = "something \n here";
echo str_replace("\n", "<br/>", $string);
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51