February 27th, 2000, 08:28 PM
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,
March 10th, 2000, 01:36 AM
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,
March 10th, 2000, 04:52 AM
Put this right before your INSERT or UPDATE statement.
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.
March 10th, 2000, 12:15 PM
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!
March 10th, 2000, 10:52 PM
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?
March 11th, 2000, 04:06 AM
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.
March 11th, 2000, 08:57 AM
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.
March 20th, 2000, 10:56 AM
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>;
June 20th, 2000, 02:57 PM
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.
June 22nd, 2000, 12:28 AM
Again... PHP has a function
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);