SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Line break <br> not showing in the output

    I have a Blob datafield in my database. When I output the data from this field using echo $row["blobdata"], the text came out OK, but the line break <br> is missed. So it ends up in one paragraph - no formatting.

    Can anyone please tell me how to output it correctly? Thanks for your help.

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What HTML doctype are you using? XHTML requires the valid XML form: <br />

  3. #3
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks for the quick reply. I'm just using normal HTML. It should have nothing to do with that.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Go into phpmyadmin (if you are using mysql) and try to browse the table in question, and see if the <br> shows up there. If it doesn't, then the line breaks aren't being stored in the first place, so there must be a problem with the script putting the data into the database or a problem with the data type that is being used.

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    nl2br($row["blobdata"]); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rraju View Post
    Go into phpmyadmin (if you are using mysql) and try to browse the table in question, and see if the <br> shows up there. If it doesn't, then the line breaks aren't being stored in the first place, so there must be a problem with the script putting the data into the database or a problem with the data type that is being used.
    I would say the script that stores the data is at issue. As far as I know, MySQL stores a BLOB as the exact byte sequence inserted into the field.

    Also, you may want to make sure your page display script isn't converting the angle brackets to entity codes.

    By the way, the last version of phpMyAdmin that I used wouldn't display the contents of a BLOB field. Unless this has changed in recent versions, you'll need MySQL Query Browser (free download from MySQL) to browse those fields.

  7. #7
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use nl4br

    it translates line returns into br on the page
    Read and share the best, worst and funniest breakup stories at :
    http://www.YouBrokeUpHow.com

  8. #8
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's awesome. It works with nl2br. Thanks so much for your help!

  9. #9
    SitePoint Addict Smola's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also use javascript to split that bad boy into an array with each <br> separating the items and then loop an output of <p> tags with each item in the array...

    Code javascript:
    str = "Hello<br>Split me up<br>Please";
     
    var pArray = str.split('<br>');
    for (var i=0; i < pArray.length; i++) {
        document.write("<p>" + pArray[i] + "</p>");
    }

    or if you are really married to php script:

    Code php:
    $str = "Hello<br>Split me up<br>Please";
     
    $pArray = explode("<br>", $str);
    for ($i=0; $i < count($pArray); $i++) {
        echo "<p>".$pArray[$i]."</p>";
    }
    Humbly,

    Smola

  10. #10
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Smola, that looks like an interesting solution. I'll look into it. Thanks^


Bookmarks

Posting Permissions

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