saving HTML to a database field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
wheeel_o
Forum Newbie
Posts: 2
Joined: Tue Nov 23, 2004 9:11 pm

saving HTML to a database field

Post 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!!
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

and no you won't need the PEAR lib.
wheeel_o
Forum Newbie
Posts: 2
Joined: Tue Nov 23, 2004 9:11 pm

Not quite what I need

Post 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?
cggreer
Forum Newbie
Posts: 14
Joined: Mon Jul 21, 2003 6:39 am

Post 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
Post Reply