New line replace with br

Discussion in 'PHP' started by Silver89, Jul 28, 2008.

  1. #1
    Hi,

    Upon submitting a form text ares I wish to replace the new lines with <br />

    Is this the correct way to do so?

    $comment = str_replace("<br />", "\n", $_POST[comment]);
    PHP:
    The security checks come after so it's safe.

    Thanks
     
    Silver89, Jul 28, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    rohan_shenoy, Jul 28, 2008 IP
    Silver89 likes this.
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    EDIT: A few seconds too late...

    www.php.net/nl2br


    This function is made for this purpose.

    No, the order of the arguments is wrong, and you should put quotes around "comment".
     
    nico_swd, Jul 28, 2008 IP
  4. cakung

    cakung Peon

    Messages:
    113
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    wow.....nice tips bro.thx :d
     
    cakung, Jul 29, 2008 IP
    Silver89 likes this.