Store html entities in database? Or convert when retrieved?

后端 未结 8 1218
自闭症患者
自闭症患者 2020-12-03 01:13

Quick question, is it a better idea to call htmlentities() (or htmlspecialchars()) before or after inserting data into the database?

8条回答
  •  暖寄归人
    2020-12-03 02:05

    I have no experience of php but generally I always convert or escape nearest to output. You don't know when your output requirements will change, for example you may want to spit out data as XML, or JSON arrays and so escaping for HTML and then storing means you're limited to using the data as HTML alone.

提交回复
热议问题