I need a way to white-list specific HTML elements and attributes, and delete HTML tags (when I say tags I mean <begin> and </end> tags, not the element and it's content) that aren't in the white-list. I figure a white-list is the best way to go about this, because otherwise I'll have to keep up with new HTML features when they enter the industry (if I go with a black-list). I also need the ability to filter attribute values, such as the value of a style attribute, so that I can filter the CSS rules of an element.
Is there any PHP built-in classes or libraries (not extensions, I don't have root access on my server) that could help me with in doing this? Or should I build my own API and use str_replace and the like to do so? If I have to build my own API, what advice would you have? What would you advise as the most secure way to use str_replace to remove elements, tags, and attributes without hackable workarounds?
Any help on this is VERY appreciated. Thanks for reading.
Cheers!