I want my forum users to be able to insert links and other allowed tags. For example I would like the following HTML in a post to display as the writer intended (i.e. as a functioning link):
<a href="http://www.example.com" rel="nofollow">A page</a>
<?php $link_string = strip_tags($link_string, '<a>'); ?>
But strip_tags doesn't protect me like htmlspecialchars does if I understand correctly. For example, incorrect HTML code using special characters can leave me vulnerable. And so can the style and onmouseover attributes for the link tag.
What is the most simple solution to allow the above link in the post while cleaning out potentially harmful characters and code? Is there anyway I can combine these two PHP functions to do this in a simple manner?