php – How to correctly write information to the sql database with a query?

Question:

How to write information to the sql base from the textarea input field while preserving paragraphs and line breaks?

I want to write down the text: "Hello everyone!

Bye everyone! "

There is a space between the lines here.

Answer:

Perhaps you need the nl2br() function.

When entering into the database, leave it unchanged, and display it like this:

echo '<div>',nl2br($text),'</div>';

Для <textarea> и <pre>:

echo '<textarea>',$text,'</textarea>';
echo '<pre>',$text,'</pre>';
Scroll to Top