PHP中htmlentities和 htmlspecialchars区别

要理解两者的差别,先看两个文档说明:
1. 简介:

    html_entity_decode — Convert all HTML entities to their applicable characters
    htmlentities — Convert all applicable characters to HTML entities
    htmlspecialchars_decode — Convert special HTML entities back to characters
    htmlspecialchars - Convert special characters to HTML entities

2. 文档:

    htmlentities:

    This function is identical to htmlspecialchars() in all ways, * except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.*

    htmlspecialchars :

    If you require all input substrings that have associated named entities to be translated, use htmlentities() instead.

说明:

htmlspecialchars 只转换(& < > ’ ” )这几个字符

而htmlentities 转换所有含有对应“html实体”的特殊字符,比如货币表示符号欧元英镑等、版权符号等。