So I have created a working comment system for my website using php and mySQL. The problem I am having is preserving the format in which the user submits their comment. I have a text box in which the user enters their comment. Let’s say the user types their comment in 3 separate paragraphs. Without any understanding of html the user would reasonably expect their carriage returns within the text box to carry over into 3 separate paragraphs when the text is displayed back on the site. This is obviously not the case as html ignores all white space. How can I make it so users comments get marked up correctly and entered into the database with p and /p tags around each paragraph so the comment comes out looking like the user would expect? How do systems such as facebook keep track of formatting issues such as line breaks without having them explicitly entered by the user?
Share
Output the comment inside
<div style="white-space: pre-wrap">. This will preserve multiple sequences of whitespaces and newlines.