Well how about the part that has to do with this? From where it fetches the data from the database, to the part where it's being displayed?
There might be another way to achieve the same, but would be more complicated since you want to strip the HTML as well. And there must be just a small error somewhere.
As you describe, it "displays the HTML as text", I guess you're not applying the function to the right variable or something along these lines.
But at the moment I can't do more than guess.