PHP/SQL: Multiple-paragraph strings

I know, second PHP-related quesion in a week. I can assure you I have been searching for along time before resporting to this. I'm certain the answer is out there, but I can't come up with suitable keywords that give me the results I need.

I have just built my first PHP-based website, which includes a simple forum that allows people to post comments. These comments are inserted into a MySQL database through a PHP script. Problem is that at the moment, I can only store/display one paragraph (even if the user creates paragraphs using the Return key in the text-field, it comes out as one big paragraph).

So my question is, how do you store multiple paragraphs in a variable? That is, when passing the values the user entered into a text-field, how can you detect when they pressed Return to start a new paragraph?

Hope that's clear enough :/

Any help is appreciated: keywords to type into google, a tutorial website -- anything to get me started.

cheers :)
 
The newline characters are most likely stored in the database, but are not shown in a HTML context where newline characters are and should be ignored.

The cleanest approach to this is to run nl2br() on the text string to display, after fetching it from the database. <br /> will be inserted before each new line to reflect this formatting in HTML.
 
This doesn't answer the question of "how do I replace line breaks with paragraph tags", which is slightly more interesting. There are a few suggestions on the nl2br man page, linked in my first post.
 
billbaloney said:
This doesn't answer the question of "how do I replace line breaks with paragraph tags", which is slightly more interesting. There are a few suggestions on the nl2br man page, linked in my first post.

Hm? :)
 
Back
Top