htmlentities() vs. htmlspecialchars()

前端 未结 12 2199
走了就别回头了
走了就别回头了 2020-11-22 02:50

What are the differences between htmlspecialchars() and htmlentities(). When should I use one or the other?

12条回答
  •  日久生厌
    2020-11-22 03:20

    htmlentities — Convert all applicable characters to HTML entities.

    htmlspecialchars — Convert special characters to HTML entities.

    The translations performed translation characters on the below:

    • '&' (ampersand) becomes '&'
    • '"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
    • "'" (single quote) becomes ''' (or ') only when ENT_QUOTES is set.
    • '<' (less than) becomes '<'
    • '>' (greater than) becomes '>'

    You can check the following code for more information about what's htmlentities and htmlspecialchars:

    https://gist.github.com/joko-wandiro/f5c935708d9c37d8940b

提交回复
热议问题