Quick question, is it a better idea to call htmlentities()
(or htmlspecialchars()
) before or after inserting data into the database?
If you don't need high performance for your website, store it as raw data and when you output it do what you want.
If you need performance then consider storing it twice: raw data to do what you want with it and another field with the filtered data. It could be seen as redundant, but CPU is expensive, while data storage is really cheap.