Reputation: 13
Just wondering the best way to do this.
Basically I have a message type website. Basically a text area which users can write stories to eachother.
At the moment when i type a story in the text area with paragraphs - for example :
"A while ago I was walking down the road when a dog attacked me.
New paragraph here talking about dogs."
at the moment would post only the first line into mysql database. Is there a way to automatically add
or /n for each time the enter key is pressed ?
But not to be visible to the user when typing in the text area.
Thank you
Upvotes: 1
Views: 84
Reputation: 3783
This is a common question which most users have.
When you echo the result from your database, you need to use nl2br
.
For example, if you your code was echo $row['story']
, it would have to be echo nl2br($row['story'])
Upvotes: 0
Reputation: 1390
Sounds like you should already have all line breaks in your db, you might just not display it correctly. Try nl2br to display the line breaks
Upvotes: 0
Reputation: 116
You can use text editor like https://www.tinymce.com/ It will automatically manage all special symbols in the text.
Many web frameworks provide such editor components too, see whether your framework has such, otherwise use tinymce it is one of the most popular.
Upvotes: 1