#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    I have a form where people enter information into a <TEXTAREA> type text box. That text is then passed to a BLOB in my MySQL database. When I retrieve that BLOB, it just shows it as one long string. How can I set this up to either preserve its formatting, or maybe let it stay stored in the blob as a text string but use PHP to format it when I pull it out (maybe a PHP question?)

    Any help would be appreciated,

    Mike
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    9
    Rep Power
    0
    Hello, I would also like to know how to retain the formatting of text stored in a Blob or Text field.

    I have a PHP form set up that allows users to type long paragraphs of data into a <TEXTAREA> text box. When the data is entered into the MySQL table, all of the paragraphs are combined into one long paragraph. All bullet lists also loose formatting so that all items of the list are combined on one line.

    Does anyone know how to correct this problem?

    All help would be greatly appreciated.

    Thanks in advance,
    SteveSoler
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    Hello,

    Put this right before your INSERT or UPDATE statement.

    $textarea=ereg_replace(10,"<br>",$textarea);

    This will take the blob $textarea, search for the ascii value 10 (line returns), replace it with "<br>", and re-store the new string back into $textarea. When you bring the text back out in an HTML format, all line returns are there.

    Hope it helps.

    Mike
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    9
    Rep Power
    0
    I haven't had a chance to try it out yet, but I'm sure it will work for me if it worked for you.

    I do have another little problem..

    I also have Product Information table for a web store that I import CSV delimited text files into. The products also use Blob/Text fields with formatted paragraphs & bullet lists of text. I am importing the text file using the following command in Telnet:

    LOAD DATA LOCAL INFILE '/home/myserver/data/products.txt' INTO TABLE products FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY 'n';

    How can I get the same formatted results for this situation?

    Thanks so much for your help!
    SteveSoler
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    Umm... Okay. I'm not an expert at this, I'm just learning as well. However, let me see if I get this straight.

    Your loading a text file with the fields seperated by a comma, and the lines ending in /n, right?

    If I'm correct, you could set up a php page to load the data from the text file, stopping at the comma, and replacing /n with <br>. However I will have to look into what the actual code will be.

    Sorry I can't be much more help than that right now, but again, I'm still learning. It is a good question though. One question for ya, what is CSV?

    Mike
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    9
    Rep Power
    0
    Hi! I am using Telnet to load a text file that I FTP uploaded to a directory on my server.

    I'm using a database program on my computer that exports data in a text format called CSV. Their definition of CSV is: "Comma-Separated text inserts quotes around each field, puts commas between fields and carriage returns (ASCII 13) between each record in an ASCII text file. Returns within fields are exported as soft returns or ASCII 11."

    I like your idea about setting up a PHP file to perform the "LOAD DATA LOCAL INFILE" command as oppose to having to use TELNET. But I would still need to know the proper code to change the "soft returns or ASCII 11" within the fields of my exported text file into <br>. I will update you if I find out this code as well.

    I do really appreciate your help. It seems as if us beginners have to stick together. No one else seems to have any advice on the matter.

    Thanks,
    SteveSoler
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    That's been my thoughts on the matter, about no one having any input on the topic, though I'm sure there are people cruising this topic that know the answer like they know their own name.

    What I'm thinking is, and I don't know the file commands of php3 yet so I don't know the code yet. But something along the lines of:

    Open the CSV file, parse the first quote, read until the next quote and store that into a variable (like $field1). Then parse the next quote, comma, quote, and read until the next quote, store that into a variable (like $field2), etc, etc. Continue until an ASCII 13 is sensed, then write all the fields to the MySQL database. Loop on that till the EOF is reached.

    Maybe you can check on php.net for the proper commands for file control (like fopen, fread, whatever), I'll look into it more tonight if I can.

    Anyone cruising thru here is free to add discussion and knowledge.
    Later,
    Mike
  14. #8
  15. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    TRY THIS:

    Whenever you come accross a difficulty, browse the PHP.net site because usually there is a shortcut.

    In this case there is an nl2br() function that converts newline carriage returns to HTML <br>;
    http://www.php.net/manual/function.nl2br.php3
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    6
    Rep Power
    0
    What I'd like to know is how to put a string--verbatim--on the database (e.g. MySQL) without having to have PHP interpret it for dynamic presentation to the database.

    I.e., how do you go directly to the DBMS from PHP without setting the string up as a command. This way we would not have to escape any quotation characters, etc.

    Bill
  18. #10
  19. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Again... PHP has a function

    addslashes($inputvariable)

    and its sister stripslashes($outputvariable)

    In other words, let's say you have a form field on a web page called 'yourcomments', and this is a place where people might put anything: commas, quotes, special characters, etc...

    Your PHP form handler should insert this into MySQL using addslashes($yourcomments), and then when you display this from the database back to a web page, you would use stripslashes($yourcomments). Sometimes it's easiest to assign another variable, as in

    $fixedcomment = addslashes($yourcomments);

    etc...

Similar Threads

  1. Replies: 4
    Last Post: July 14th, 2005, 08:04 PM
  2. importing text file
    By min in forum PHP Development
    Replies: 12
    Last Post: November 26th, 2003, 05:18 AM
  3. TEXT or BLOB field problems
    By eschatology2020 in forum PHP Development
    Replies: 3
    Last Post: November 8th, 2003, 06:45 PM
  4. How to get overflow in this table cell?
    By kippie in forum HTML Programming
    Replies: 4
    Last Post: July 15th, 2003, 06:46 PM
  5. BLOB text replaced by "?????" - sorry newbie
    By PeteX in forum MySQL Help
    Replies: 5
    Last Post: May 27th, 2001, 12:19 PM

IMN logo majestic logo threadwatch logo seochat tools logo