Inserting text from textarea into MySQL database without losing formatting

后端 未结 2 635
后悔当初
后悔当初 2020-12-11 06:02

I am trying to add text from a textarea on my site into a MySQL database.

Below is the PHP code that is adding the text to the database.

if (isset($_         


        
相关标签:
2条回答
  • 2020-12-11 06:48

    Your text, unless you're using a rich-text editor, such as Mark-down (as here on Stackoverflow), is styled by your CSS, not by the contents of the textarea itself.

    If the problem is preservation of new-lines, then you could run the string through the nl2br($text) function before storing in, or retrieving from, the database.

    I'd suggest on retrieval would be better, but that's just my opinion (and I can't offer any evidence to back it up).

    0 讨论(0)
  • 2020-12-11 06:55

    Or you can use

    echo nl2br($test);
    
    0 讨论(0)
提交回复
热议问题