htmlentities() vs. htmlspecialchars()

前端 未结 12 2231
走了就别回头了
走了就别回头了 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:04

    Because:

    • Sometimes you're writing XML data, and you can't use HTML entities in a XML file.
    • Because htmlentities substitutes more characters than htmlspecialchars. This is unnecessary, makes the PHP script less efficient and the resulting HTML code less readable.

    htmlentities is only necessary if your pages use encodings such as ASCII or LATIN-1 instead of UTF-8 and you're handling data with an encoding different from the page's.

提交回复
热议问题