Using htmlspecialchars is sufficient when pasting inside HTML code. The way it encodes characters makes it impossible to βtear outβ the resulting text. Thus, it cannot create other elements, not script segments, etc.
However, in all other htmlspecialchars situations this will not be automatic enough. For example, when you use it to insert code in any area of ββJavaScript, for example, when you fill out a JavaScript string, you will need additional methods to ensure security. In this case, addslashes may help.
So, depending on where you paste the resulting text, htmlspecialchars gives you either sufficient security or not. As mentioned in the function name, this simply promises security for HTML.
source share