Can you use a custom filter with PHP filter_var() and filter_input()
<p><a href="http://us.php.net/manual/en/book.filter.php" rel="nofollow">PHP Filters</a> are pretty cool, but what do you do if the filters don't quite match what you want?  Can you create a custom filter?</p>
