swenn
swenn

Reputation: 33

Formatting text from MySQL

I've been wondering how could I apply different styles to text that is taken from MySQL db. Let's assume the user makes a blog post with 5 paragrphs in the content field. When I add the post to the database, it is saved as one continuous string, right? Now, when I want to make the new post visible on the main page, the text is also shown as one continuous string, even though the user made 5 separate paragraphs.

I tried to make a little research about the topic, but didn't find anything useful. How are the paragraphs added when taking the text from the mysql database? It would be interesting to know, how big blogging sites (or even StackOverflow) deal with such things. I'm open to all interesting ideas and references!

Upvotes: 0

Views: 359

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 79024

If the user used the 'Enter' key to separate paragraphs then there are 'newline' characters in the text. To render line breaks in HTML use <br />. You can use nl2br() before you display the text. This converts newline \n to <br />.

Upvotes: 1

Related Questions