One minor point about htmlspecialchars() on the way OUT rather than on the way in: it's possibly more efficient to do it on the way in since that saves some processing time when visitors browse your website.
Of course, you lose it at the other end but then the data is only input once and then viewed many thousands of times (hopefully!).
This comment is more to illustrate a principle rather than anything else. Stripping out nasties on the way in rather than on the way out is unlikely to make a lot of difference to most page load times but it's good to think about efficent coding. A little bit here and a little bit there just might add up to a lot..
While I'm in efficient coding rant mode, creating a whole extra $clean array (above) can be avoided by just writing addslashes(trim($POST['var'])) where you need them - or even htmlspecialchars(addslashes(trim($POST['var']))) 🙂
Or, if you are expecting an integer value: intval($_POST['var']) is all you need - form forgers who try to submit strings to that POST key won't have any joy.