Differences between htmlspecialchars() and htmlentities()

The function htmlentities is identical to the function htmlspecialchars in many ways. But there are some differences in terms of conversions. Following are few differences between htmlentities and htmlspecialchars functions:

htmlentities

htmlspecialchars

1. It converts all applicable characters to HTML entities 1. It convert special characters to HTML entities
2. Example echo htmlentities('<Il était>.'); // Output:&lt;Il &eacute;tait&gt;. 2. Example echo htmlspecialchars('<Il était>.'); // Output: &lt;Il était&gt;.
3. htmlentities is not good for XML data 3. htmlspecialchars is useful in case of XML data

Comments