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
    mat
    mat is offline
    Regular Coder
    Join Date
    Jul 2002
    Posts
    199
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replcing line breaks with <p></p>?

    I have a form which lets the user enter text and add this to the database.
    When this text is pulled from mySQL database, I use the function 'nl2br' to convert \r\n to <br>.

    So my html text comes out as

    This is a paragraph<br><br>
    This is another paragraph<br><br>


    ...but I really need it to come out as:

    <p>This is a paragraph</p>
    <p>This is another paragraph</p>


    Does anyone have suggestions on how to do this ?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    $str 
    str_replace("\n","</p><p>",$str);
    echo 
    '<p> ' $str ' </p>';
    ?>


  •  

    Posting Permissions

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