Preserve Line Breaks From TextArea When Writing To MySQL

前端 未结 7 2220
我在风中等你
我在风中等你 2020-11-22 12:25

I\'m using a textarea to enable users to input comments. However, if the users enters new lines, the new lines don\'t appear when they are outputted. Is there any way to m

7条回答
  •  眼角桃花
    2020-11-22 12:45

    why make is sooooo hard people when it can be soooo easy :)

    //here is the pull from the form
    $your_form_text = $_POST['your_form_text'];
    
    
    //line 1 fixes the line breaks - line 2 the slashes
    $your_form_text = nl2br($your_form_text);
    $your_form_text = stripslashes($your_form_text);
    
    //email away
    $message = "Comments: $your_form_text";
    mail("destination_email@whatever.com", "Website Form Submission", $message, $headers);
    

    you will obviously need headers and likely have more fields, but this is your textarea take care of

提交回复
热议问题