将用户输入插入到用户设置的mysql数据库中(带换行符)

I am looking to insert a user's input from a textarea into a mysql database. As of now, if the user types the following:

"Hello.


hello."

It will be inserted into the database without the line breaks. How can I fix this?

If using PHP, i suggest using $message = nl2br($message);

This will turn line breaks into br's for you.

You are probably using phpMyAdmin to tell that the line breaks aren't there. If that's the case, then it is lying to you. phpMyAdmin displays the contents as HTML, and line breaks are transformed to a single white space.

Even if you're just outputting the value and not using phpMyAdmin, your HTML will still collapse the white space. To preserve the format, output it between <pre> tags or in a span with css style white-space: pre

Actually the line breaks are inserted in the database, you just can't see them, because they are " ", this are Line Feed and Carriage Return, read more about them here

I believe that you should store the data like this: no conversion made, when you write the content to your HTML, you simply have to do an nl2br($content).

And it's also easy to edit, because when outputting that content to an textarea tag, it automatically recognizes the " "