Using PHP, how can I remove all tags except anchors (<a>) from an HTML string, and then convert all the reserved characters into their HTML entities except for the <a> tags?
For example, I would to convert this:
<p><a href="http://www.example.com/">Example.com</a> says that 5 < 6.</p>
into this:
<a href="http://www.example.com/">Example.com</a> says that 5 < 6.
I went with HTML Purifier. Click here for the demo which converts the original example properly.
The code for doing this is: