PHP already has a function to do this.
$foo = strip_tags($foo);
Will remove all HTML from $foo.
Now if you want to allow certain tags, like bold and italic, for example strip_tags accepts an argument to do so:
$foo = strip_tags($foo,"<b>,<i>");
Hope that helped.