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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts

    nl2br - Removing line drops

    Ok so im using the nl2br tag in my code but i find it makes my code look sloppy when in the code is shows the line drops with the <br /> tags in it. Is there a way of making my code a single straight line with the br's included??
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    Post your code. That way, we'd be able to help you pretty it up better.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    PHP Code:
    $query mysql_query("SELECT * FROM `shout` WHERE ORDER BY timestamp `desc`");
    while(
    $row mysql_fetch_array($query)){
        
    $id $row["id"];
        
    $name $row["name"];
        
    $body $row["body"];

        
    $body nl2br($body);

    echo 
    $name.'<br/>'.$body.'<br/><br/>';


    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #4
    New Coder
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    49
    Thanks
    0
    Thanked 3 Times in 3 Posts
    That is because nl2br() only converts \n (linebreak) to <br />. To make the string "flat" you need to erase the \r (carriage return) too. This can be done by using str_replace()

    ex:
    PHP Code:
    $string "Here´s a little text
    with some
    linebreaks in it"
    ;

    echo 
    nl2br($string); 
    Output:
    Code:
    Here´s a little text<br />
    with some<br />
    linebreaks in it
    if you use
    PHP Code:
    echo str_replace("\r\n"'<br />'$string); 
    the output becomes:
    Code:
    Here´s a little text<br />with some<br />linebreaks in it


  •  

    Posting Permissions

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