In PHP when submitting strings to the database should I take care of illegal characters using htmlspecialchars() or use a regular expression?

前端 未结 6 1997
说谎
说谎 2020-11-22 03:18

I am working on a form with the possiblity for the user to use illegal/special characters in the string that is to be submitted to the database. I want to escape/negate thes

6条回答
  •  Happy的楠姐
    2020-11-22 04:05

    First of all, you should sanitize things when displaying, not before inserting into the database. SQL injections are another story, but probably off-topic.

    Second, if you don't need your users to be able to post HTML at all, htmlspecialchars is all you need. It takes care of all the special characters in HTML.

提交回复
热议问题