Best practice. Do I save html tags in DB or store the html entity value?

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-05T22:43:40Z Indexed on 2010/05/05 23:38 UTC
Read the original article Hit count: 291

Filed under:
|
|
|

Hi Guys,

I was wondering about which way i should do the following. I am using the tiny MCE wysiwyg editor which formats the users data with the right html tags. Now, i need to save this data entered into the editor into a database table.

Should I encode the html tags to their corresponding entities when inserting into the DB, then when i get the data back from the table, not have the encode it for XSS purposes but I'd still have to use eval for the html tags to format the text.

OR

Do i save the html tags into the database, then when i get the data back from the database encode the html tags to their entities, but then as the tags will appear to the user, I'd have to use the eval function to actually format the data as it was entered.

My thoughts are with the first option, I just wondered on what you guys thought.

© Stack Overflow or respective owner

Related posts about php

Related posts about html-entities