htmlentities() might help to protect you from SQL injection, but it won't do a damn thing against XSS attacks.
If HTML entities works properly, and it is used properly, shouldn't it prevent XSS since an attacker who inputs something like <script>alert("xss")</script> would simply see the message displayed back to them instead of the browser actually executing it?