There are two advantages to using htmlentities() :
- XSS Prevention
- Convert special characters to corresponding HTML objects, for example, it converts a copyright symbol to
© . In HTML content, you should use the appropriate HTML object instead of pasting an unprocessed special character.
To prevent XSS, you can use htmlspecialchars() instead, but it will only convert some basic characters to HTML objects, namely quotation marks, ampersands, and less / more characters.
In response to your question, you should use htmlentities() to output any content that may contain user input or special characters.
source share