Page 1 of 1

saving HTML to a database field

Posted: Tue Nov 23, 2004 9:19 pm
by wheeel_o
This may belong in another Topic, but ...

Is there a simple function that will allow me to save text input by the user in a form as HTML in my SQL database to preserve the paragraph breaks? I can't seem to find a simple function, will I need a PEAR lib or something?

Thanks in advance!!

Posted: Wed Nov 24, 2004 2:56 am
by djot

Posted: Wed Nov 24, 2004 3:10 am
by phpScott
and no you won't need the PEAR lib.

Not quite what I need

Posted: Wed Nov 24, 2004 9:48 am
by wheeel_o
Hmm.. actually strip-tags() is the exact opposite of what I need.

Ok, when I enter text into a field like the "post a reply" as I am doing now, the backend of this website preserves all of the line breaks between paragraphs.

The spaces between paragraphs will be remembered, stored away in the database. Then the site SELECT's back the data to display it and all of the line breaks are there, just as they should be.

My app, however, stores all of the line breaks to the database but a SELECT function to the database returns only a long sequence of text no matter how many breaks I put in it.

I dont care if my database looks clunky or ful of tags, I just want to be able to call back the line breaks without manually adding br tags.

Am I simply doing something wrong?

Posted: Fri Dec 03, 2004 2:59 am
by cggreer
If you're using MySQL, you can substitute the \n escape character for newlines. When you read the record back out from the database, the \n will appear as a new line (ie. you won't have \n's all through the data when you read it back out).

Reference links:
MySQL Strings info: http://dev.mysql.com/doc/mysql/en/String_syntax.html