Saving \n as <br> to database

Discussion in 'PHP' started by qwikad.com, Oct 21, 2015.

  1. #1
    I tried this but it's not chaning new lines to <br>
    
    <textarea name="addesc" id="addesc"><?php echo $data['addesc']; ?></textarea>
    
    Code (markup):
    
    $data['addesc'] = preg_replace("/\r\n|\r/", "<br />", $_POST["addesc"]); $data['addesc'] = trim($data['addesc'])
    
    Code (markup):
    As such there's no $_POST["addesc"] on the post.php page. There's $_POST["do"]. I tried it too. No results.

    I am sure I am missing something. How is something like that done exactly?
     
    Solved! View solution.
    qwikad.com, Oct 21, 2015 IP
  2. #2
    ThePHPMaster, Oct 21, 2015 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,361
    Likes Received:
    1,713
    Best Answers:
    31
    Trophy Points:
    475
    #3
    This did it:
    $data['addesc'] = htmlentities(nl2br($data['addesc']));
    Code (markup):
     
    qwikad.com, Oct 22, 2015 IP