Results 1 to 4 of 4

Thread: Formatting text in the BLOB field

  1. #1
    Join Date
    Feb 2003
    Location
    VA
    Posts
    10

    Question Formatting text in the BLOB field

    I am developing a MySql database that will take large amounts of text (media stories) and display it on the web.
    The problem I have is the formatting of the story gets lost (the hard returns). How do I keep the original format
    after the story has been put into the database. The story is being submitted via a web form.

    Thanks
    Last edited by bygmony; 02-03-2003 at 01:22 PM.

  2. #2
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    When displaying in html, hard returns don't do anything, so you'll need to replace them with <br> tags. You can replace the hard returns when you load the story, or when you display it.

    Also, it would make more sense to use a TEXT field instead of a BLOB field (case insensitive searching)

  3. #3
    Join Date
    Feb 2003
    Location
    VA
    Posts
    10

    Got answer

    PKG in the PHP forum passed on this to me and it worked great.

    nl2br()

    example:
    1. echo nl2br($storyString);
    2. <?php echo nl2br($row_rsFullStory['Story']); ?>

    This allowed the form I copy & pasted into to keep the formatting.

  4. #4
    Join Date
    Mar 2003
    Location
    Paris
    Posts
    1
    You can use TEXT fields, why BLOBs?
    TEXT fields can support several characters sets, and, nice feature, you can use fulltext indexing on them.

    You problem doesn't come from MySQL but from HTML, as explained in another reply to your post.

    To get the line breaks displayed properly, you have 2 solutions:
    - Either you filter the input to replace '\n' by <br>
    - Or when you display your stored text you enclose your text by <pre> and </pre>.

    Example:
    <?PHP
    echo "<pre>$myrow[textfield]</pre>\n";
    ?>

Posting Permissions

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