Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Line breaks in textarea

    Hi.. I have problem with a textarea in a form I made... line breaks are output as \r\n, and I can't seem to fix it.

    I tried nl2br() on the string, but it just returns the same string, it's not working like it should for some reason.

    I also tried doing $str = str_replace("\r\n","<br />",$str); and this, for some reason, is not working either.

    I tried doing this to the string variable both before insertion to the database, and also after retrieval, at the time it's gonna be displayed, and nothing works... I keep getting the \r\n.

    What can be going on here?

  • #2
    New Coder
    Join Date
    May 2003
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $str preg_replace("(\r\n|\r|\n)","<br />",$str); 
    Use preg_replace instead of str_replace. Depending on the Operating System the line break could be a \r\n, a \r, or a \n

    The nl2br() should have worked...as it looks for any of the three...strange.
    cpCommerce - Finally a template based open-source e-commerce solution


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •