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

前端 未结 6 1926
说谎
说谎 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条回答
  •  广开言路
    2020-11-22 04:08

    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.

    Users can go a lot beyond than that actually.

    I want to escape/negate these characters in the string and have been using htmlspecialchars(). However, I would like to know if there is a better/faster method.

    Use HTML Purifier:

    HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist.

    and decide for yourself :)

提交回复
热议问题